/*------------------------------------------------------------------*/ /* SAMPLE CODE */ /* */ /* SAS/ETS Software: Applications Guide 2, Version 6, First Edition */ /* Publication book code: 56009 */ /* */ /* Each sample begins with a comment that states the */ /* chapter and page number where the code is located. */ /*------------------------------------------------------------------*/ /* Chapter 2 pages 17-19 */ /* Creating the TANDY Data Set */ data tandy; input r_m r_f tandy @@; /* Creating New Variables */ r_tandy = tandy - r_f; r_mkt = r_m - r_f; /* Labeling New Variables */ label r_m='Market Rate of Return' r_f='Risk-Free Rate of Return' tandy='Rate of Return for Tandy Corporation' r_tandy='Risk Premium for Tandy Corporation' r_mkt='Risk Premium for Market'; cards; -.045 .00487 -.075 .010 .00494 -.004 .050 .00526 .124 .063 .00491 .055 .067 .00513 .176 .007 .00527 -.014 .071 .00528 .194 .079 .00607 .222 .002 .00645 -.100 -.189 .00685 -.206 .084 .00719 .086 .015 .00690 .085 .058 .00761 -.046 .011 .00761 -.135 .123 .00769 .122 .026 .00764 -.094 .014 .00772 -.148 .075 .00715 .096 -.013 .00728 .006 .095 .00789 .250 .039 .00802 -.005 -.097 .00913 -.037 .116 .00819 .170 .086 .00747 .037 .124 .00883 .032 .112 .01073 .143 -.243 .01181 -.105 .080 .00753 -.038 .062 .00630 .256 .086 .00503 .041 .065 .00602 .446 .025 .00731 .167 .015 .00860 .157 .006 .00895 -.015 .092 .01137 .212 -.056 .00977 .022 -.014 .01092 -.139 -.009 .01096 .082 .067 .01025 .299 -.008 .01084 .092 .064 .01255 .136 -.003 .01128 -.167 -.033 .01154 .032 -.031 .01169 -.063 -.164 .01054 -.008 .062 .01003 .241 .069 .00816 -.037 -.039 .00740 -.046 -.079 .00949 .059 -.101 .00946 -.101 -.028 .01067 -.051 .041 .00972 .053 .003 .00908 -.163 -.078 .00914 .023 -.006 .00714 .050 .122 .00503 .017 .008 .00563 -.026 .136 .00620 .454 .049 .00614 .273 .014 .00648 -.042 .065 .00646 .091 .028 .00599 .032 .043 .00686 -.004 .097 .00652 .084 .080 .00649 -.010 .048 .00673 -.168 -.017 .00714 -.123 -.034 .00668 -.048 .000 .00702 -.083 -.082 .00678 -.058 .066 .00683 .082 -.012 .00693 .095 -.029 .00712 -.190 -.030 .00672 -.100 .003 .00763 -.008 -.003 .00741 .120 -.058 .00627 -.231 .005 .00748 -.037 -.058 .00771 .029 .146 .00852 .079 .000 .00830 -.100 -.035 .00688 -.096 -.019 .00602 .027 -.001 .00612 .005 .097 .00606 .170 .012 .00586 .119 .008 .00650 .094 -.010 .00601 -.133 .019 .00512 .091 -.003 .00536 .087 .012 .00562 -.119 .005 .00545 .063 -.055 .00571 -.011 .026 .00577 .098 .059 .00540 .021 .013 .00479 .098 -.009 .00548 -.040 .049 .00523 .096 .048 .00508 -.047 -.009 .00444 -.058 .049 .00469 .094 .004 .00478 -.092 -.076 .00458 -.078 .049 .00343 .018 -.047 .00416 -.108 .018 .00418 .242 .000 .00420 .094 -.005 .00382 -.023 .148 .00454 .130 .065 .00437 .174 .037 .00423 -.118 -.025 .00207 -.119 .004 .00438 -.026 .038 .00402 .045 .055 .00455 .087 .015 .00460 .027 -.015 .00520 .088 -.260 .00358 -.246 -.070 .00288 -.190 .073 .00277 .040 ; /* Printing the First Five Observations */ proc print data=tandy (obs=5) label; var r_tandy r_mkt r_m r_f tandy; /* Titling the Data Set */ title 'TANDY Corporation CAPM Example'; title2 'First Five Observations TANDY Data'; run; /* Chapter 2 page 19 */ proc plot data=tandy vpct=65; plot r_tandy * r_mkt = 'a'; title2 'Plot of Risk Premiums'; title3 'Tandy Corporation versus the Market'; run; /* Chapter 2 page 21 */ proc autoreg data=tandy; model r_tandy = r_mkt / dwprob; run; /* Chapter 2 page 23 */ proc syslin data=tandy noprint; model r_tandy = r_mkt; test r_mkt = 1; run; /* Chapter 2 page 25 */ proc autoreg data=tandy; model r_tandy = r_mkt / noprint; output out=tandyout p=p r=r ucl=u lcl=l alphacli=.10; run; proc print data=tandyout (obs=5) label; var r_tandy p r u l; title 'TANDY Corporation CAPM Example'; title2 'First Five Observations of the'; title3 'TANDYOUT Data Set'; run; /* Chapter 2 page 25 */ proc plot data=tandyout vpct=70; plot r * r_mkt = '*' / vref=0.0; /* vertical reference line */ title2 'OLS Residuals versus Market Risk Premium'; title3; run; /* Chapter 2 page 27 */ proc plot data=tandyout; plot /* Plotting R_TANDY vs R_MKT, Points Labeled 'a' */ r_tandy * r_mkt = 'a' /* Plotting Predicted R_TANDY, p, vs R_MKT */ p * r_mkt = 'p' /* Plotting Upper Confidence Limit, u, vs R_MKT */ u * r_mkt = 'u' /* Plotting Lower Confidence Limit, l, vs R_MKT */ l * r_mkt = 'l' / overlay; title2 'Actual and Predicted Risk Premium'; title3 'versus Market Risk Premium'; run; /* Chapter 2 pages 27-29 */ goptions device=\ob device-driver-name\obe ; goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); goptions reset=symbol; /* Sorting the Data */ proc sort data=tandyout; by r_mkt; run; /* Creating Arrays for Plotting the Data */ data regdata(keep=y_value pt_type r_mkt); set tandyout; label pt_type='Observation Type'; array regvar{4} r_tandy p l u; array varlabel{4} $12 _temporary_ ('Actual' 'Predicted' 'Lower Limits' 'Upper Limits'); do i=1 to 4; y_value=regvar{i}; /* create 1 record per data point */ pt_type=varlabel{i}; /* label type of data point */ output; end; run; /* Plotting the Data */ proc gplot data=regdata; plot y_value*r_mkt=pt_type / haxis=axis1 hminor=4 vaxis=axis2 vminor=4; symbol1 v=* h=3.5 pct font=swissb color=black; symbol2 i=join font=swissb l=2 color=blue; symbol3 i=join font=swissb l=1 color=green; symbol4 i=join font=swissb l=2 color=red; axis1 order=(-.3 to .15 by .05); axis2 label=(angle=90 'Tandy Corp. Risk Premium') order=(-.5 to .5 by .25); title1 "Actual and Predicted Values"; title2 "with Upper and Lower Confidence Limits"; run; quit; /* Chapter 2 page 32 */ data prod; input y l k @@; ln_y = log(y); ln_l = log(l); ln_k = log(k); label ln_y = 'Natural Log of US GNP Index' ln_l = 'Natural Log of Labor-Input Index' ln_k = 'Natural Log of Capital-Input Index'; cards; 274.0 213.4 97.2 279.9 223.6 105.9 297.6 228.2 113.0 297.7 221.9 114.9 328.9 228.8 124.1 351.4 239.0 134.5 360.4 241.7 139.7 378.9 245.2 147.4 375.8 237.4 148.9 406.7 245.9 158.6 416.3 251.6 167.1 422.8 251.5 171.9 418.4 245.1 173.1 445.7 254.9 182.5 457.3 259.6 189.0 466.3 258.1 194.1 495.3 264.6 202.3 515.5 268.5 205.4 544.1 275.4 215.9 579.2 285.3 225.0 615.6 297.4 236.2 631.1 305.0 247.9 ; proc print data=prod (obs=5) label; var y ln_y l ln_l k ln_k; title 'Cobb-Douglas Production Function Example'; title2 'First Five Observations of PROD Data Set'; run; /* Chapter 2 pages 33-36 */ proc syslin data=prod; model ln_y = ln_l ln_k; run; proc syslin data=prod; model ln_y = ln_l ln_k / noprint; test ln_l + ln_k = 1; run; proc syslin data=prod; model ln_y = ln_l ln_k; restrict ln_l + ln_k = 1; run; /* Chapter 3 pages 43-45 */ /* Creating the ACON Data Set */ data acon; input yr di c @@; label di='Real per Capita Disposable Inc. in 1982$' c='Real per Capita Consumption in 1982$'; cards; 29 4091 3868 30 3727 3569 31 3534 3400 32 3043 3081 33 2950 3013 34 3100 3088 35 3359 3236 36 3738 3523 37 3836 3628 38 3557 3517 39 3812 3667 40 4017 3804 41 4528 3981 42 5138 3912 43 5276 3949 44 5414 4026 45 5285 4236 46 5115 4632 47 4820 4625 48 5000 4650 49 4915 4661 50 5220 4834 51 5308 4853 52 5379 4915 53 5515 5029 54 5505 5066 55 5714 5287 56 5881 5349 57 5909 5370 58 5908 5357 59 6027 5531 60 6036 5561 ; /* Printing the First Five Observations */ proc print data=acon (obs=5) label; var yr di c; title 'Annual Consumption Function Example'; title2 'First Five Observations of ACON Data'; run; /* Plotting C and DI vs Year */ proc plot data=acon vpct=60; plot c * yr = 'c' di * yr = 'd' / overlay; title2 'Consumption and Disposable Income'; title3 'versus Year'; run; /* Plotting C vs DI */ proc plot data=acon vpct=60; plot c * di; title2 'Consumption versus Disposable Income'; title3; run; /* Chapter 3 pages 46-47 */ proc syslin data=acon; model c=di / dw; run; proc syslin data=acon out=acn_out noprint; model c=di / dw; output residual=resid predicted=p; run; proc print data=acn_out; var yr c p resid; title2 'Printout of ACN_OUT Data Set'; run; /* Chapter 3 page 49 */ goptions reset=symbol; proc gplot data=acn_out; plot c*di=1 p*di=2 / overlay haxis=axis1 vaxis=axis2; symbol1 h=1.5 pct v=* font=swissb color=black; symbol2 i=join h=1.5 pct font=swissb l=1 color=blue; axis1 label=(h=3.5 pct 'Per Capita Disposable Income') order=(2500 to 6500 by 500) minor=(number=4); axis2 label=(h=3.5 pct angle=90 'Per Capita Consumption') order=(2500 to 6000 by 500) minor=(number=4); title 'Actual and Predicted C versus DI'; title2 '(in real 1982 dollars)'; run; /* Chapter 3 page 49 */ proc plot data=acn_out vpct=60; plot resid*yr='*' / vref=0; title2 'Residuals versus Year'; title3 'Model without Intercept Dummy'; run; /* Chapter 3 page 51 */ /* Adding Intercept Dummy Variable to Consume Data */ data acon1; set acon; /* Creating Intercept Dummy Variable */ if 41 '01MAR79'd then int_dum = 1; else int_dum = 0; /* Slope Dummy */ slp_dum = int_dum * r_mkt; label int_dum='Intercept Dummy' slp_dum='Slope Dummy'; run; /* Fitting Model with Slope Dummy Variable */ proc syslin data=gpu1 out=gpu_out; model r_gpu = r_mkt int_dum slp_dum; output predicted=p; run; /* Chapter 3 pages 60-61 */ /* Separating Pre and Post Accident Values */ data gpu_out1(keep=y_value pt_type r_mkt); set gpu_out; label pt_type='Observation Type'; array regvar{2} r_gpu p; do i=1 to 2; y_value=regvar{i}; pt_type=i+2*(date > '01MAR79'd); output; end; run; /* Sorting the Data */ proc sort data=gpu_out1 by y_value pt_type; run; /* Formatting the Data */ proc format; value ptfmt 1='Actual pre TMI' 2='Predict pre TMI' 3='Actual post TMI' 4='Predict post TMI'; run; goptions reset=symbol; /* Plotting the Data */ proc gplot data=gpu_out1 plot y_value*r_mkt=pt_type / haxis=axis1 vaxis=axis2; symbol1 h=3 pct v=plus color=black; symbol2 font=swissb l=1 i=join color=blue; symbol3 h=3 pct v=circle color=green; symbol4 font=swissb l=3 i=join color=red; axis1 order=(-.3 to .2 by .1) minor=(number=1); axis2 label=(angle=90 'GPU Risk Premium') order=(-.4 to .4 by .1) minor=(number=1); title1 'Risk Premiums, GPU versus MKT'; title2 'Actual and Predicted'; format pt_type ptfmt.; run; quit; /* Chapter 3 page 63 */ proc syslin data=gpu1; model r_gpu = r_mkt int_dum slp_dum / noprint; chowtest:test slp_dum = int_dum = 0; run; /* Sorting the Data */ proc sort data=gpu; by int_dum; run; /* Fitting a Regression Line Over Entire Period */ proc syslin data=gpu; model r_gpu = r_mkt; run; /* Fitting Regression Lines Over Sub-periods */ proc syslin data=gpu; model r_gpu = r_mkt; by int_dum; run; /* Chapter 4 page 69 */ data inflate; input cpi m1 @@; retain date '1oct49'd; date=intnx('qtr',date,1); format date yyq.; cards; 52.3 112.033 52.7 113.667 54.3 114.933 55.2 115.933 56.9 117.133 57.2 118.200 57.2 119.700 57.8 121.900 57.7 123.500 57.6 124.533 58.0 125.800 58.6 127.067 58.7 127.567 58.9 128.433 59.1 128.633 58.8 128.733 59.5 129.100 59.7 129.400 59.6 130.633 59.9 131.967 60.4 133.500 60.8 134.300 61.2 134.867 61.5 135.100 62.0 135.567 62.5 135.933 63.2 135.967 63.8 136.600 64.5 136.867 64.8 136.933 65.4 136.967 65.4 136.233 65.7 136.067 65.8 137.633 66.2 139.000 66.4 140.700 67.0 142.600 67.4 143.800 67.7 144.533 68.0 143.633 68.4 143.000 68.6 142.767 68.8 143.900 68.9 144.233 68.8 144.833 69.2 146.033 69.5 146.867 69.6 148.300 70.2 149.167 70.4 149.833 70.6 149.533 71.0 150.433 71.3 151.833 71.4 153.333 71.6 154.800 72.1 156.400 72.3 157.333 72.5 158.833 72.9 161.433 73.1 163.400 73.7 164.500 74.1 165.800 74.6 167.700 74.9 170.500 75.7 173.333 76.6 175.467 77.0 175.267 77.7 175.467 78.2 177.167 78.5 179.733 79.2 183.867 80.2 186.600 81.2 189.100 82.1 192.767 82.9 196.667 84.0 200.667 85.0 204.067 86.0 206.167 87.4 207.333 88.5 208.533 89.8 210.367 90.9 213.133 91.7 215.833 93.0 218.667 94.4 222.400 95.7 228.000 ; proc print data=inflate (obs=5); var date cpi m1; title 'INFLATION Model Example'; title2 'First Five Observations INFLATE Data'; run; /* Chapter 4 pages 70-71 */ data inflate1; set inflate; /* Calculating Percentage Changes in P and M */ p=100*(cpi-lag12(cpi))/lag12(cpi); m=100*(m1-lag12(m1))/lag12(m1); /* Calculating Lag in Money Supply M1 */ m_lag14=lag14(m); /* Labeling Variables */ label p='Quarterly % Change in Prices' m='Quarterly % Change in Money Supply, M1' m_lag14='M1 Money Supply Lagged 14 Quarters'; /* Subsetting Data */ if date < '1JAN58'D then delete; run; /* Fitting of the Model by OLS */ proc autoreg data=inflate1; model p = m_lag14 / noprint; output out=infl_out r=resid p=pred; run; /* Plotting Residuals Versus Time */ proc plot data=infl_out vpct=55; plot resid * date = '*' / vref=0.0; title 'INFLATION Model Example'; title2 'OLS Residuals versus Time'; run; /* Chapter 4 page 73 */ proc autoreg data=inflate1; model p = m_lag14 / dw=4 dwprob; run; /* Chapter 4 page 76 */ proc autoreg data=inflate1; model p = m_lag14 / nlag=1 method=ml maxit=40 converge=.0001 dw=1 dwprob; run; /* Chapter 4 page 77 */ proc autoreg data=inflate1; model p = m_lag14 / nlag=2 method=ml maxit=40 dw=1 dwprob; run; /* Chapter 4 page 80 */ proc model data=inflate1; parameters b0 b1; endogenous p; exogenous m_lag14; p = b0 + b1*m_lag14; %ar(ar,2,p) fit p; run; /* Chapter 4 pages 81-82 */ data expend; input exp pop aid income @@; label exp='State & Local Govt Exp in Million of $' pop='State Population in Thousands' aid='Per Capita Govt Aid for Education in $' income='Per Capita Personal Income in $'; cards; 698 325 570 5222 368 346 369 4269 411 460 235 3703 543 533 180 5209 571 571 170 5222 475 634 201 4128 521 680 195 3766 587 716 252 4083 512 755 180 3711 526 774 123 4279 940 816 202 5153 699 969 184 4513 704 1026 186 3664 823 1076 277 3512 821 1127 196 3741 1052 1528 134 4451 1250 1795 252 3624 1523 1963 150 4273 1014 2008 199 3345 1766 2185 201 4339 1427 2256 255 3188 1551 2268 132 4535 1920 2364 183 4600 1767 2633 190 3837 1512 2688 153 3500 2108 2884 113 4316 2546 3080 145 5414 2063 3306 181 3634 3070 3418 184 4601 2104 3521 193 3476 2691 3738 196 3565 3528 3877 163 4343 3392 4048 135 5017 2446 4072 175 3708 3757 4526 116 4279 3197 4733 178 3956 3156 4747 151 4307 3037 4765 131 4396 2938 5221 141 3868 3457 5286 103 4364 5166 5796 190 4825 4771 7347 114 4450 5911 7349 141 5379 7799 9013 147 4982 6867 10722 112 4572 8935 11244 156 5162 7246 11604 141 4085 8840 11905 136 4545 22750 18367 240 5275 20052 20411 200 5087 ; proc print data=expend (obs=5) label; var exp pop aid income; title 'Government Expenditure Model'; title2 'First Five Observations EXPEND Data'; run; proc plot data=expend vpct=55; plot exp * (pop aid income) = '*'; title2 'Dependent versus Independent Variables'; run; /* Chapter 4 pages 84-85 */ proc autoreg data=expend; model exp = pop aid income; /* Fitting the model */ output out = exp_out /* Output data set creation */ p = pred /* Create predicted values */ r = resid; /* Create residuals */ run; proc print data=exp_out (obs=5); run; proc plot data=exp_out vpct=55; plot resid * (pop aid income) / vref=0.0; title2 'Residuals versus Independent Variables'; run; /* Chapter 4 pages 88-89 */ /* Creating Squares and Absolute Values of Residuals */ proc model data=expend noprint; parameters b0 b1 b2 b3; endogenous exp; exogenous pop aid income; exp = b0 + b1*pop + b2*aid + b3*income; resid_ab = abs(resid.exp); resid2 = resid.exp**2; fit exp / out=exp_out1; outvars resid_ab resid2; run; /* Plotting Squares and Absolute Values of Residuals */ proc plot data=exp_out1 vpct=55; plot (resid_ab resid2) * pop; title2 'Absolute Value and Square of Residuals'; title3 'versus Population, POP'; run; /* Chapter 4 pages 90-91 */ /* Creating the Squared OLS Residuals */ proc model data=expend noprint; parameters b0 b1 b2 b3; endogenous exp; exogenous pop aid income; exp = b0 + b1*pop + b2*aid + b3*income; resid2 = resid.exp**2; fit exp / out=exp_out2; outvars resid2; run; /* Performing the White Test */ proc autoreg data=exp_out2; model resid2 = pop; run; /* Performing the White Test */ proc autoreg data=exp_out2; model resid2 = pop / noint; run; /* Chapter 4 page 93 */ /* Creating Squares and Crossproduct for White Test */ data expend1; set expend; pop2 = pop**2; income2 = income**2; pop_inc = pop*income; run; /* Fitting Model and Creating Squared Residuals */ proc model data=expend1; parameters b0 b1 b2 b3; endogenous exp; exogenous pop aid income; exp = b0 + b1*pop + b2*aid + b3*income; resid2 = resid.exp**2; fit exp / out=exp_out3; /* Adding Variables to Output Data */ id pop2 income2 pop_inc; outvars resid2; run; /* Performing a White Test */ proc autoreg data=exp_out3; model resid2 = pop pop2 income income2 pop_inc; run; /* Chapter 4 page 94 */ /* Creating Transformed Variables */ data expend2; set expend; expcorr = exp/pop; popcorr = 1/pop; aidcorr = aid/pop; inccorr = income/pop; run; /* OLS Regression of Transformed Data */ proc autoreg data=expend2; model expcorr = popcorr aidcorr inccorr; run; /* Chapter 4 page 96 */ /* Creating Weight Variable, WT */ data expend3; set expend; wt = 1/pop**2; run; /* Printing Five Observations of POP and WT */ proc print data=expend3 (obs=5) label; var pop wt; title2 'First Five Observations EXPEND3 Data'; run; /* Performing Weighted Regression */ proc syslin data=expend3; model exp = pop aid income; weight wt; run; /* Chapter 5 pages 101-102 */ data mcon; format date monyy.; input date:monyy5. di_n c_n cpi @@; c = c_n/cpi; di = di_n/cpi; c_1 = lag(c); label di='Real Disposable Income in Billions 1982$' c='Real Consumption in Billions of 1982$' c_1='1 Month Lagged Real C in Billions 1982$'; cards; SEP82 2283.2 2140.1 .979 OCT82 2299.8 2157.9 .982 NOV82 2321.7 2178.7 .980 DEC82 2332.7 2188.1 .976 JAN83 2344.3 2196.9 .978 FEB83 2339.2 2202.4 .979 MAR83 2353.7 2219.3 .979 APR83 2382.0 2249.9 .986 MAY83 2397.4 2276.9 .992 JUN83 2406.9 2296.3 .995 JUL83 2438.6 2318.1 .999 AUG83 2433.2 2329.8 1.002 SEP83 2457.7 2332.4 1.007 OCT83 2499.1 2366.2 1.010 NOV83 2528.7 2378.4 1.012 DEC83 2555.9 2402.9 1.013 JAN84 2585.2 2437.2 1.019 FEB84 2614.3 2414.2 1.024 MAR84 2635.9 2440.8 1.026 APR84 2637.8 2469.6 1.031 MAY84 2637.0 2489.7 1.034 JUN84 2653.5 2510.7 1.037 JUL84 2675.9 2508.1 1.041 AUG84 2688.0 2522.3 1.045 SEP84 2709.4 2547.3 1.050 OCT84 2710.9 2540.7 1.053 NOV84 2725.5 2585.2 1.053 DEC84 2749.5 2588.1 1.053 JAN85 2771.2 2620.3 1.055 FEB85 2764.6 2633.6 1.060 MAR85 2757.9 2653.6 1.064 APR85 2832.9 2654.0 1.069 MAY85 2890.2 2701.1 1.073 JUN85 2829.2 2693.7 1.076 JUL85 2835.1 2709.8 1.078 AUG85 2837.4 2742.1 1.080 SEP85 2847.5 2788.4 1.083 OCT85 2877.2 2764.0 1.087 NOV85 2887.5 2781.1 1.090 DEC85 2933.7 2818.2 1.093 JAN86 2944.9 2828.6 1.096 FEB86 2958.1 2819.2 1.093 MAR86 2974.6 2822.1 1.088 APR86 3010.6 2837.0 1.086 MAY86 3004.5 2859.1 1.089 JUN86 3004.2 2858.3 1.095 JUL86 3013.5 2882.5 1.095 AUG86 3022.2 2903.4 1.097 SEP86 3037.0 2967.1 1.102 OCT86 3047.4 2937.4 1.103 NOV86 3061.2 2944.5 1.104 DEC86 3081.4 3002.4 1.105 JAN87 3112.3 2965.1 1.112 FEB87 3149.5 3030.0 1.116 MAR87 3157.6 3039.5 1.121 APR87 3044.2 3065.0 1.127 MAY87 3163.6 3073.4 1.131 JUN87 3169.2 3101.3 1.135 JUL87 3192.5 3123.5 1.138 AUG87 3213.9 3158.9 1.144 SEP87 3227.0 3152.5 1.150 OCT87 3293.7 3158.5 1.153 NOV87 3281.6 3165.5 1.154 DEC87 3331.6 3193.7 1.154 JAN88 3341.9 3225.3 1.157 FEB88 3381.4 3235.1 1.160 MAR88 3412.6 3266.2 1.165 APR88 3399.3 3268.6 1.171 MAY88 3441.8 3295.5 1.175 JUN88 3477.0 3331.8 1.180 JUL88 3507.4 3345.2 1.185 AUG88 3516.8 3370.1 1.190 SEP88 3536.0 3374.3 1.198 OCT88 3585.0 3414.8 1.202 NOV88 3560.8 3427.8 1.203 DEC88 3590.8 3448.6 1.205 JAN89 3618.6 3460.8 1.211 FEB89 3669.1 3475.7 1.216 MAR89 3697.5 3479.4 1.223 APR89 3676.5 3518.9 1.231 MAY89 3696.2 3527.5 1.238 JUN89 3719.3 3539.0 1.241 JUL89 3740.1 3569.0 1.244 AUG89 3741.0 3597.8 1.246 SEP89 3749.0 3599.6 1.250 OCT89 3772.9 3605.0 1.256 NOV89 3802.1 3618.1 1.259 DEC89 3823.9 3653.4 1.261 JAN90 3861.2 3687.3 1.274 FEB90 3886.1 3695.0 1.280 MAR90 3915.9 3706.9 1.287 APR90 3915.5 3715.8 1.289 MAY90 3927.7 3717.4 1.292 JUN90 3945.7 3752.2 1.299 ; proc print data=mcon (obs=5); title 'Monthly Consumption Function Example'; title2 'First Five Observations MCON Data'; run; /* Chapter 5 pages 103-105 */ proc autoreg data=mcon; model c=c_1 di / lagdep=c_1; run; proc autoreg data=mcon; model c=c_1 di / method=yw nlag=1; run; /* Chapter 5 pages 108-109 */ data almon; input cap_exp appro @@; retain date '1oct52'd; date=intnx('qtr',date,1); format date yyq.; label cap_exp='Capital Expenditures' appro='Appropriations'; cards; 2071 1660 2077 1926 2078 2181 2043 1897 2062 1695 2067 1705 1964 1731 1981 2151 1914 2556 1991 3152 2129 3763 2309 3903 2614 3912 2896 3571 3058 3199 3309 3262 3446 3476 3466 2993 3435 2262 3183 2011 2697 1511 2338 1631 2140 1990 2012 1993 2071 2520 2192 2804 2240 2919 2421 3024 2639 2725 2733 2321 2721 2131 2640 2552 2513 2234 2448 2282 2429 2533 2516 2517 2534 2772 2494 2380 2596 2568 2572 2944 2601 2629 2648 3133 2840 3449 2937 3764 3136 3983 3299 4381 3514 4786 3815 4094 4093 4870 4262 5344 4531 5433 4825 5911 5160 6109 5319 6542 5574 5785 5749 5707 5715 5412 5637 5465 5383 5550 5467 5465 ; proc print data=almon (obs=5); var date cap_exp appro; title 'Almon Polynomial Distributed Lag Example'; title2 'First Five Observations ALMON Data'; run; /* Chapter 5 pages 110-111 */ proc pdlreg data=\ob SAS-data-set\obe ; model y = x z(p,d,q); run; proc pdlreg data=almon; model cap_exp = appro(8,2,2) / dw=4 dwprob; run; /* Chapter 5 page 114 */ proc pdlreg data=almon; model cap_exp = appro(8,2,2) / method=yw nlag=2 dw=1 dwprob; run; /* Chapter 5 page 116 */ proc pdlreg data=almon; model cap_exp = appro(7,2,2) / method=yw nlag=2 dw=1 dwprob; run; /* Chapter 5 page 118 */ proc pdlreg data=almon; model cap_exp = appro(7,2,2,last) / method=yw nlag=2 dw=1 dwprob; run; /* Chapter 5 page 121 */ proc pdlreg data=almon; model cap_exp = appro(7,3,3) / nlag=2 dw=1 dwprob; run; /* Chapter 5 page 123 */ proc model data=almon; parameters int; /* int = intercept */ endogenous cap_exp; %pdl(appropdl,8,2) cap_exp = int + %pdl(appropdl,appro); fit cap_exp; run; /* Chapter 6 pages 130-131 */ /* Creating the KLEIN Data Set */ data klein; input year c p wp i k x wg g t; time = year-1919; p_1 = lag(p); x_1 = lag(x); k_1 = lag(k); wt = wp+wg; label c = 'Consumer Expenditures' p = 'Profits' wp= 'Private Wage Bill' i = 'Investment Expenditures' k = 'Capital Stock' k_1='Capital Stock Lagged One Period' x = 'Total Output of Private Industry' wg= 'Government Wage Bill' g = 'Government Expenditures' t = 'Taxes'; cards; 1919 . . . . 180.1 . . . . 1920 39.8 12.7 28.8 2.7 182.8 44.9 2.2 2.4 3.4 1921 41.9 12.4 25.5 -.2 182.6 45.6 2.7 3.9 7.7 1922 45.0 16.9 29.3 1.9 184.5 50.1 2.9 3.2 3.9 1923 49.2 18.4 34.1 5.2 189.7 57.2 2.9 2.8 4.7 1924 50.6 19.4 33.9 3.0 192.7 57.1 3.1 3.5 3.8 1925 52.6 20.1 35.4 5.1 197.8 61.0 3.2 3.3 5.5 1926 55.1 19.6 37.4 5.6 203.4 64.0 3.3 3.3 7.0 1927 56.2 19.8 37.9 4.2 207.6 64.4 3.6 4.0 6.7 1928 57.3 21.1 39.2 3.0 210.6 64.5 3.7 4.2 4.2 1929 57.8 21.7 41.3 5.1 215.7 67.0 4.0 4.1 4.0 1930 55.0 15.6 37.9 1.0 216.7 61.2 4.2 5.2 7.7 1931 50.9 11.4 34.5 -3.4 213.3 53.4 4.8 5.9 7.5 1932 45.6 7.0 29.0 -6.2 207.1 44.3 5.3 4.9 8.3 1933 46.5 11.2 28.5 -5.1 202.0 45.1 5.6 3.7 5.4 1934 48.7 12.3 30.6 -3.0 199.0 49.7 6.0 4.0 6.8 1935 51.3 14.0 33.2 -1.3 197.0 54.4 6.1 4.4 7.2 1936 57.7 17.6 36.8 2.1 199.8 62.7 7.4 2.9 8.3 1937 58.7 17.3 41.0 2.0 201.8 65.0 6.7 4.3 6.7 1938 57.5 15.3 38.2 -1.9 199.9 60.9 7.7 5.3 7.4 1939 61.6 19.0 41.6 1.3 201.2 69.5 7.8 6.6 8.9 1940 65.0 21.1 45.0 3.3 204.5 75.7 8.0 7.4 9.6 1941 69.7 23.5 53.3 4.9 209.4 88.4 8.5 13.8 11.6 ; /* Printing the KLEIN Data Set */ proc print data=klein (obs=5) label; var year c i wp k x g t wg p; title 'KLEIN Model 1 Example'; title2 'First Five Observations KLEIN Data'; run; /* Chapter 6 page 133 */ /* Invoking PROC MODEL */ proc model data=klein outmodel=kl_mod graph; parms a1-a4 b1-b4 c1-c4; /* Model Equations */ c=a1+a2*p+a3*lag(p)+a4*wt; i=b1+b2*p+b3*lag(p)+b4*lag(k); wp=c1+c2*x+c3*lag(x)+c4*time; /* Identities */ x=c+i+g; p=x-wp-t; k=lag(k)+i; wt=wp+wg; /* Endogenous and Exogenous Variables */ endo c i wp x p wt k; exo p_1 k_1 x_1 time t g wg; /* Variable Included in Output Data Set */ id year; /* Estimating the Model */ fit c i wp / dw sur covs; run; /* Chapter 6 page 138 */ proc model data=klein; parms a1-a4 b1-b4 c1-c4; c=a1+a2*p+a3*lag(p)+a4*wt; i=b1+b2*p+b3*lag(p)+b4*lag(k); wp=c1+c2*x+c3*lag(x)+c4*time; x=c+i+g; k=lag(k)+i; wt=wp+wg; endo c i wp x p wt k; exo p_1 k_1 x_1 time t g wg; id year; fit c i wp / dw 3sls fsrsq; instruments p_1 k_1 x_1 time t g wg; run; /* Chapter 6 page 140 */ proc model data=klein; parms a1-a4 b1-b4 c1-c4; c=a1+a2*p+a3*lag(p)+a4*wt; i=b1+b2*p+b3*lag(p)+b4*lag(k); wp=c1+c2*x+c3*lag(x)+c4*time; x=c+i+g; p=x-wp-t; k=lag(k)+i; wt=wp+wg; %ar(ar_c,1, c) endo c i wp x p wt k; exo p_1 k_1 x_1 time t g wg; id year; fit c i wp / dw 3sls; instruments p_1 k_1 x_1 time t g wg; run; /* Chapter 6 page 143 */ data pork; input yr q trn yn h cpi expn bn; tr = trn/cpi; p = tr/q; y = yn/cpi; exp = expn/cpi; b = bn/cpi; label yr = 'Year' q = 'Quantity Produced in Millions of lbs' p = 'Average Pork Price Real $ per lb' y = 'Real Personal Income in Billions' h = 'Hogs Kept for Breeding in Thousands' cpi = 'US CPI 1982-1984 = 100' exp = 'US Farms Total Expenses in Millions' b = 'Real Price Beef, 100 lbs Carlots'; cards; 65 18252.141 3732.747 552.0 7915 .315 33650 28.62 66 19148.989 4314.511 600.8 8752 .324 36508 35.44 67 20636.444 3921.254 644.5 8988 .334 38181 35.94 68 21034.221 3881.759 707.2 9252 .348 39525 37.30 69 20600.325 4700.280 772.9 9205 .367 42115 41.58 70 21822.826 4750.844 831.8 10630 .388 44424 44.72 71 22832.335 4144.396 894.0 9748 .405 47367 45.63 72 20918.802 5387.954 981.6 9147 .418 52315 51.41 73 20154.425 7736.731 1101.7 8988 .444 65562 65.78 74 19976.384 7166.161 1210.1 8823 .493 72210 53.48 75 16835.178 8183.583 1313.4 7358 .538 75043 43.09 76 18160.337 7756.478 1451.4 8388 .569 82741 52.00 77 19020.900 7543.411 1607.5 8688 .606 88885 51.55 78 19466.200 9038.467 1812.4 8857 .652 103249 74.61 79 22617.129 9294.814 2034.0 10368 .726 123305 100.48 80 23401.728 9157.469 2258.5 9481 .824 133139 92.45 81 21812.966 10000.500 2520.9 8358 .909 139444 84.06 82 19657.921 10836.950 2670.8 7414 .965 139954 78.96 83 21206.207 9914.131 2838.6 8113 .996 137897 78.48 84 20199.620 9816.436 3108.7 7401 1.039 143819 74.70 85 20166.989 9132.223 3325.3 6997 1.076 131926 74.13 86 19461.055 9823.886 3526.2 6435 1.096 125503 71.31 87 20445.529 10424.037 3766.4 7040 1.136 127693 83.70 88 21669.557 9283.451 4070.8 7530 1.183 132063 88.61 89 21849.658 9497.491 4384.3 7330 1.240 142566 94.43 ; proc print data=pork (obs=5) label; var yr q p b h; title 'Pork Market Supply and Demand Example'; title2 'First Five Observations PORK Data'; run; /* Chapter 6 page 145 */ proc model data=pork; var p q h b; parms d0-d2 s0-s2; eq.demand = d0 + d1*p + d2*b - q; eq.supply = s0 + s1*p + s2*h - q; fit demand supply / 2sls; instruments yr y h cpi exp b; run; /* Chapter 6 page 146 */ proc syslin data=pork liml; instruments yr y h cpi exp b; model q = p b; run; /* Chapter 6 page 147 */ proc syslin data=pork liml outest=pork_est; instruments yr y h cpi exp b; model q = p b / noprint; run; proc print data=pork_est; title2 'Fitted Pork Market Demand Data'; run; /* Chapter 6 page 148 */ data pork1; set pork_est; keep intercep q b p p_est q_est1 q_est2; if _n_ < 3 then delete; do p_est = .25 to 1.1 by .05; q_est1 = intercep + b*100 + p*p_est; /* Beef prices low */ q_est2 = intercep + b*200 + p*p_est; /* Beef prices high */ label p_est = 'Estimated Price' q_est1 = 'Estimated Quantity, Low Beef Price' q_est2 = 'Estimated Quantity, High Beef Price'; output; end; run; proc print data=pork1 (obs=5); title2 'Pork Data for Demand Schedules'; run; proc plot data=pork1 vpct=60; plot p_est * q_est1 = 'L' p_est * q_est2 = 'H' / overlay; title2 'Pork Demand Shift as Beef Price Changes'; run; /* Chapter 6 pages 149-150 */ proc means data=pork noprint; var q p b; output out=pork_out mean= q_mean p_mean b_mean; run; data pork2; merge pork1 pork_out; keep p b q_mean p_mean b_mean; if _n_ > 1 then delete; run; proc print data=pork2; title2 'Pork Data for Elasticities'; run; data pork3; set pork2; p_elas = p*(p_mean/q_mean); b_elas = b*(b_mean/q_mean); label p_elas = 'Own Price Elasticity' b_elas = 'Cross-Price Elasticity (with Beef)'; run; proc print data=pork3 label; var p_elas b_elas; title2 'Pork Demand Elasticities'; run; /* Chapter 7 pages 153-156 */ /* Creating the PC Data Set */ data pc; input year percent @@; yr = year - 80; cards; 81 11.1 82 20.2 83 62.4 84 82.2 85 91.0 86 94.9 87 96.0 88 96.8 ; /* Printing the PC Data Set */ proc print data=pc; var yr percent; title 'Logistic Curve Example'; title2 'PC Data'; run; goptions reset=symbol; proc gplot data=pc; plot percent*year / haxis=axis1 vaxis=axis2; symbol1 v=A h=1 font=swissb i=join l=1; axis1 order=(81 to 88 by 1) minor=none offset=(3); axis2 order=(0 to 100 by 10) minor=(number=3) label=(angle=90 'Percent of Schools'); title 'Personal Computer Use'; run; quit; /* Chapter 7 page 158 */ /* Adding Quadratic and Cubic Terms */ data pc1; set pc; yr2 = yr*yr; yr3 = yr2*yr; title 'Logistic Curve Example'; title2; run; /* Fitting the Cubic Polynomial Model */ proc model data=pc1; parameters a b c d; percent = a + b*yr + c*yr2 + d*yr3; fit percent; run; /* Chapter 7 page 159 */ proc model data=pc1; parms a b c; percent = a + b*yr + c*yr2; fit percent; run; /* Chapter 7 page 160 */ /* Generating the PC_OUT Output Data Set */ proc model data=pc1 noprint; parms a b c; percent = a + b*yr + c*yr2; fit percent / out=pc_out; predp=pred.percent; outvars predp; id percent year; run; goptions reset=symbol; /* Creating Graph */ proc gplot data=pc_out; plot percent*year predp*year / overlay haxis=axis1 vaxis=axis2; symbol1 v=A h=1 font=swissb i=join l=1 color=black; symbol2 font=swissb i=join l=3 color=blue; axis1 label=(Year') order=(81 to 88 by 1) offset=(3) minor=none; axis2 label=(angle=90 'Percent of Schools') order=(0 to 100 by 10) minor=(number=3); title 'Actual and Predicted Percent vs. Year'; title2 'Quadratic Polynomial Model'; run; quit; /* Chapter 7 page 162 */ proc model data=pc; parms a b c; percent = a/(1 + exp(b + c*yr)); fit percent start=(a=100 c=-.005) / converge=.05; run; /* Chapter 7 page 165 */ proc model data=pc outmodel=pc_mod; parms a b c; percent = a/(1 + exp(b + c*yr)); fit percent start=(a=100 b=100 10 c=-.5 -1 -1.5) / converge=.0001 method=marquardt; run; /* Chapter 7 page 168 */ /* Fitting Model and Creating PC_OUT1 Output Data Set */ proc model data=pc noprint; parms a b c; percent = a/(1 + exp(b + c*yr)); fit percent start=(a=100 b=100 10 c=-.5 -1 -1.5) / converge=.0001 method=marquardt out=pc_out1; predp=pred.percent; outvars predp; id percent year; run; quit; goptions reset=symbol; /* Plotting Actual and Predicted Values */ proc gplot data=pc_out1; plot percent * year predp * year / overlay haxis=axis1 vaxis=axis2; axis1 order=(81 to 88 by 1) offset=(3) minor=none; axis2 label=(angle=90 'Percent of Schools') minor=(number=3) order=(0 to 100 by 10); symbol1 h=1 pct v=A font=swissb color=black; symbol2 font=swissb i=join l=3 color=blue; title 'Fit of Logistic Model'; run; quit; /* Chapter 7 page 170 */ data ces; input k l q @@; label k ='Capital Input' l ='Labor Input' q ='Output'; cards; 8 23 106.00 9 14 81.08 4 38 72.80 2 97 57.34 6 11 66.79 6 43 98.23 3 93 82.68 6 49 99.77 8 36 110.00 8 43 118.93 4 61 95.05 8 31 112.83 3 57 64.54 6 97 137.22 4 93 86.17 2 72 56.25 3 61 81.10 3 97 65.23 9 89 149.56 3 25 65.43 1 81 36.06 4 11 56.92 2 64 49.59 3 10 43.21 6 71 121.24 ; proc print data=ces (obs=5) label; title 'CES Production Function Example'; title2 'First Five Observations CES Data'; run; /* Chapter 7 page 171 */ proc g3grid data=ces out=ces_grid; grid k*l=q / spline smooth=.01 axis1=1 to 9 by .5 axis2=10 to 100 by 10; run; proc g3d data=ces_grid; plot k*l=q / rotate=75 tilt=80 zmin=10 zmax=160 yticknum=3 xticknum=5; title 'Two-Input Production Surface Plot'; run; quit; /* Chapter 7 page 172 */ proc model data=ces; parms g r v d; q = g*((d*k**r) + (1-d)*l**r)**(v/r); fit q start = (g=15 d=.6 r=-.3 v=.5) / converge =.0001; run; /* Chapter 7 page 175 */ proc model data=ces; parms g r v d; q = g*(((d*k)**r) + ((1-d)*l)**r)**(v/r); fit q start = (g=50 5 d=.65 .55 r=-.2 -.4 v=.7 -.8) / converge =.00005; run; /* Chapter 7 page 176 */ proc model data=ces; parms g r v d; control v 1; q = g*((d*k**r) + (1-d)*l**r)**(v/r); fit q start = (g=5 50 d=.6 r=-.25) / converge =.001; run; /* Chapter 8 pages 182-183 */ data demand; input st year q cpi pn yn @@; /* Creating Real P and Y by */ /* Deflating Nominal P and Y by CPI */ p = pn/cpi; y = yn/cpi; /* Labeling Variables */ label q = 'Sales in Trillions of BTUs' cpi = 'Consumer Price Index' p = 'Real Electricity Price' y = 'Real Personal Income'; /* Labeling Cross-Sections */ if st=1 then state = 'NC'; if st=2 then state = 'SC'; if st=3 then state = 'VA'; cards; 1 1970 50.0 .388 5.47 3256 1 1971 53.9 .405 5.89 3424 1 1972 56.6 .418 6.30 3721 1 1973 63.1 .444 6.53 4258 1 1974 63.4 .493 8.03 4612 1 1975 64.8 .538 9.32 4943 1 1976 68.2 .569 10.44 5409 1 1977 74.6 .606 11.21 5935 1 1978 77.3 .652 12.02 6607 1 1979 77.2 .726 12.60 7359 1 1980 83.2 .824 13.91 7999 1 1981 85.1 .909 15.96 8646 1 1982 81.9 .965 18.50 9148 1 1983 86.1 .996 19.42 9982 1 1984 91.9 1.039 19.57 11001 1 1985 91.6 1.076 20.48 11664 1 1986 100.7 1.096 21.17 12453 1 1987 107.5 1.136 21.59 13353 1 1988 109.9 1.183 21.90 14304 2 1970 25.1 .388 5.66 2992 2 1971 26.8 .405 6.10 3142 2 1972 28.1 .418 6.52 3448 2 1973 31.7 .444 6.69 3885 2 1974 31.9 .493 8.30 4258 2 1975 33.6 .538 9.62 4665 2 1976 35.3 .569 10.48 5126 2 1977 38.6 .606 11.45 5628 2 1978 40.0 .652 11.35 6242 2 1979 39.0 .726 12.70 7027 2 1980 42.9 .824 13.69 7589 2 1981 44.6 .909 15.73 8109 2 1982 46.0 .965 17.61 8605 2 1983 47.1 .996 18.97 9288 2 1984 49.7 1.039 19.20 10171 2 1985 50.0 1.076 20.54 10734 2 1986 55.0 1.096 20.89 11336 2 1987 57.7 1.136 21.03 12078 2 1988 58.6 1.183 20.90 12926 3 1970 39.4 .388 6.13 3720 3 1971 41.1 .405 6.28 3899 3 1972 44.5 .418 6.51 4258 3 1973 50.1 .444 6.90 4868 3 1974 50.3 .493 9.06 5265 3 1975 54.2 .538 11.07 5770 3 1976 58.5 .569 11.12 6276 3 1977 62.1 .606 12.73 6865 3 1978 63.7 .652 13.30 7624 3 1979 63.9 .726 14.95 8605 3 1980 67.3 .824 17.80 9827 3 1981 70.2 .909 18.15 10385 3 1982 69.4 .965 19.81 11386 3 1983 73.7 .996 20.56 12505 3 1984 74.1 1.039 19.53 13498 3 1985 77.0 1.076 19.49 14467 3 1986 86.1 1.096 19.48 15456 3 1987 91.7 1.136 19.62 16539 3 1988 96.2 1.183 19.29 17675 ; /* Printing the First Five Observations */ proc print data=demand (obs=5) label; var state year q p y; title 'TSCS Electricity Demand Example'; title2 'First Five Observations DEMAND Data'; run; /* Chapter 8 pages 184-185 */ /* Formatting the Cross-Sections */ proc format; value stfmt 1='NC' 2='SC' 3='VA'; run; goptions reset=symbol; /* Plotting the Electricity Demand */ proc gplot data=demand; plot q*year=st / haxis=axis1 vaxis=axis2; symbol1 v=N font=swissb i=join l=1 color=black; symbol2 v=S font=swissb i=join l=1 color=blue; symbol3 v=V font=swissb i=join l=1 color=green; axis1 order=(1970 to 1988 by 2) minor=(number=1) offset=(3); axis2 order=(20 to 110 by 10) minor=(number=3) label=(angle=90 'Electricity Sales'); title1 'Residential Demand for Electricity'; title2 '(in trillions of BTU)'; format st stfmt.; run; quit; /* Chapter 8 page 186 */ /* Sorting the Data */ proc sort data=demand; by state year; run; /* Checking for Autocorrelation */ proc autoreg data=demand; model q = p y / dw=4 dwprob; by state; run; /* Chapter 8 page 189 */ proc arima data=demand; by state; identify var=q; run; quit; /* Chapter 8 pages 191-192 */ /* Sorting the Data by Time Series ID */ proc sort data=demand out=dem_out (keep=year q); by year; run; /* Transposing the Data */ /* Rows Become Columns */ proc transpose data=dem_out out=dem_out1 (drop=_name_ _label_); by year; run; /* Renaming the Data Columns */ data dem_out2; set dem_out1; rename col1=q_nc col2=q_sc col3=q_va; run; /* Printing the Data */ proc print data=dem_out2 (obs=5); title2 'First Five Observations DEM_OUT2 Data'; run; /* Checking for Cross-Sectional Correlation */ proc corr data=dem_out2; var q_nc q_sc q_va; run; /* Chapter 8 page 193 */ /* Sorting the Data */ /* First by Cross-Section ID, Second by Time-Series ID */ proc sort data=demand; by state year; run; /* Fitting the TSCS Model */ proc tscsreg data=demand; model q = p y / parks rho; id state year; run; /* Chapter 8 page 195 */ /* Creating Cross-Sectional Dummy Variables */ data demand1; set demand; if st=2 then sc_dum = 1; else sc_dum = 0; if st=3 then va_dum = 1; else va_dum = 0; run; /* Fitting the TSCS Model */ proc tscsreg data=demand1; model q = sc_dum va_dum p y / parks rho; id state year; run; /* Chapter 8 pages 196-197 */ /* Creating OUTEST Data Set */ proc tscsreg data=demand1 noprint outest=dem_est (keep=_type_ intercep p y sc_dum va_dum); model q = sc_dum va_dum p y / parks; id st year; run; /* Creating Parameter Estimate Data Set */ data dem_est1(drop=_type_); set dem_est(where=(_type_='PARMS') rename=(y=p_y p=p_p sc_dum=p_sc_dum va_dum=p_va_dum)); run; /* Creating Predicted Values */ data demand2; /* Merging First Observation with All */ /* Observations to Calculate Predicted Values */ if _n_=1 then set dem_est1; set demand1(keep=q st year p y); drop p_nc_dum; /* Setting NC_DUM Equal to Zero */ retain p_nc_dum 0; array p_dum{3} p_nc_dum p_sc_dum p_va_dum; array pred_val{3} pred_nc pred_sc pred_va; array act_val{3} q_nc q_sc q_va; pred_val{st}=intercep + p*p_p + y*p_y + p_dum{st}; act_val{st}=q; run; goptions reset=symbol; /* Plotting Actual and Predicted Values */ proc gplot data=demand2; plot q_nc*year=1 q_sc*year=2 q_va*year=3 pred_nc*year=4 pred_sc*year=5 pred_va*year=6 / overlay haxis=axis1 vaxis=axis2; symbol1 h=2 pct v=N font=swissb i=join l=1 color=black; symbol2 h=2 pct v=S font=swissb i=join l=1 color=blue; symbol3 h=2 pct v=V font=swissb i=join l=1 color=green; symbol4 h=2 pct v=star color=red; symbol5 h=2 pct v=circle color=gray; symbol6 h=2 pct v=diamond color=lib; /* light blue */ axis1 order=(1970 to 1988 by 2) minor=(number=1) offset=(3); axis2 order=(20 to 110 by 10) minor=(number=3) label=(angle=90 'Electricity Sales'); title1 'Residential Demand for Electricity'; title2 '(in trillions of BTU)'; run; quit; /* Chapter 9 pages 205-206 */ data budget; input year gfundn gnpn fed_revn pop cpi @@; gfund = gfundn / cpi; gnp = gnpn / cpi; fed_rev = fed_revn / cpi; label gfund = 'Real General Fund in Millions' gnp = 'Real US GNP in Billions' fed_rev = 'Real Federal IRS Collections in Billions' pop = 'NC Population in Thousands' cpi = 'US CPI 82-84 = 100'; cards; 73 1214.0 1359.3 237.8 5382 .444 74 1358.0 1472.8 269.0 5461 .493 75 1451.0 1598.4 293.8 5535 .538 76 1572.0 1782.8 302.5 5593 .569 77 1870.0 1990.5 358.1 5668 .606 78 2060.0 2249.7 399.8 5739 .652 79 2337.0 2508.2 460.4 5802 .726 80 2639.0 2732.0 519.4 5882 .824 81 2846.0 3052.6 606.8 5957 .909 82 3078.0 3166.0 632.2 6018 .965 83 3279.0 3405.7 627.2 6078 .996 84 3814.0 3772.2 680.5 6167 1.039 85 4337.0 4010.3 742.9 6258 1.076 86 4695.0 4235.0 782.3 6327 1.096 87 5181.0 4524.3 886.3 6409 1.136 88 5552.0 4880.6 935.1 6489 1.183 89 5928.5 5200.8 1013.5 6571 1.240 ; proc print data=budget (obs=10) label; var year gfund gnp fed_rev pop; title 'General Fund Revenues Example'; title2 'First Ten Observations BUDGET Data'; run; /* Chapter 9 page 207 */ proc plot data=budget vpct=60; plot gfund*year; title2 'General Fund Revenues versus YEAR'; run; /* Chapter 9 page 208 */ proc model data=budget; parms d f h; endo gfund; exo gnp pop; gfund = d + f*gnp + h*pop; fit gfund / dw; run; /* Chapter 9 page 209 */ proc model data=budget outmodel=bud_mod1; parms d1 f1 h1; gfund = d1 + f1*gnp + h1*pop; %ar(ar_gf, 1, gfund); endo gfund; exo gnp pop; id year; fit gfund / dw; run; /* Chapter 9 pages 211-212 */ /* Simulating the Model */ proc model data=budget model=bud_mod1 noprint; solve gfund / simulate out=bud_out(rename=(gfund=s_gfund1)); run; /* Merging Data Sets */ data bud_outp; merge budget bud_out; by year; run; /* Printing the Simulation Values */ proc print data=bud_outp; var year gfund s_gfund1; title2 'GFUND Simulations'; title3 'GFUND Model with POP'; run; goptions reset=symbol; proc gplot data=bud_outp; plot gfund*year=1 s_gfund1*year=2 / overlay haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join l=1 color=black; symbol2 v=P font=swissb color=blue; axis1 offset=(2,2)pct order=(73 to 89 by 1) label=none; axis2 order=(2000 to 5000 by 500) minor=(number=1) label=(a=-90 r=90 'GENERAL FUND'); legend1 label=none value=('Actual GFUND' 'Simulated GFUND'); title 'General Fund Revenues'; title2 'Actual and Simulated, 1973-1989'; run; quit; /* Chapter 9 page 215 */ proc model data=budget model=bud_mod1; solve gfund / simulate theil stats out=bud_out1(rename=(gfund=s_gfund1)); run; /* Chapter 9 page 217 */ proc model data=budget outmodel=bud_mod2; parms d2 f2 h2; gfund = d2 + f2*gnp + h2*fed_rev; %ar(ar_gf, 1, gfund); endo gfund; exo gnp fed_rev; id year; fit gfund / dw; run; /* Chapter 9 page 218 */ proc model data=budget model=bud_mod2; solve gfund / simulate theil stats out=bud_out2(rename=(gfund=s_gfund2)); run; /* Chapter 9 pages 221-222 */ /* Creating EXTRAP Data Set for What-If Simulation */ data extrap; set budget; if year >= 82 then do; fed_revl=667.547*(1+.010)**(year-81); fed_revm=667.547*(1+.025)**(year-81); fed_revh=667.547*(1+.040)**(year-81); gfund=.; end; run; /* Printing Data */ proc print data=extrap (firstobs=7); var year fed_rev fed_revl fed_revm fed_revh; title2 'EXTRAP Data Set for What-If Simulations'; run; goptions reset=symbol; /* Plotting Data */ proc gplot data=extrap; plot fed_rev*year=1 fed_revl*year=2 fed_revm*year=3 fed_revh*year=4 / overlay haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join l=1 color=black; symbol2 i=join v=L font=swissb l=3 color=blue; symbol3 v=M font=swissb color=green; symbol4 i=join v=H font=swissb l=3 color=red; axis1 offset=(2,2)pct order=(73 to 89 by 1) label=none; axis2 order=(500 to 900 by 100) minor=(number=1) label=(a=-90 r=90 'FEDERAL REVENUE'); legend1 label=none value=('Actual FED_REV' 'Low FED_REV' 'Mid FED_REV' 'High FED_REV'); title 'Actual and What-If Federal Revenue'; title2 '1973-1989'; run; quit; /* Chapter 9 page 223 */ data bud_lo(drop=fed_rev fed_revm fed_revh rename=(fed_revl=fed_rev)) bud_mid(drop=fed_rev fed_revl fed_revh rename=(fed_revm=fed_rev)) bud_hi(drop=fed_rev fed_revl fed_revm rename=(fed_revh=fed_rev)); set extrap; if fed_revl=. then fed_revl=fed_rev; if fed_revm=. then fed_revm=fed_rev; if fed_revh=. then fed_revh=fed_rev; run; /* Printing an Updated Data Set */ proc print data=bud_lo; var year fed_rev; title2 'FED_REV from BUD_LO Data Set'; run; /* Chapter 9 pages 224-225 */ /* Performing the What-If Simulation */ proc model model=bud_mod2 noprint; /* Predicted Values */ solve gfund / simulate start=10 data=budget out=out_p(drop=_type_ _mode_ _errors_ rename=(gfund=p_gfund)); /* Low What-If FED_REV Simulation */ solve gfund / simulate start=10 data=bud_lo out=out_lo(drop=_type_ _mode_ _errors_ rename=(gfund=gfund_l)); /* Mid What-If FED_REV Simulation */ solve gfund / simulate start=10 data=bud_mid out=out_mid(drop=_type_ _mode_ _errors_ rename=(gfund=gfund_m)); /* High What-If FED_REV Simulation */ solve gfund / simulate start=10 data=bud_hi out=out_hi(drop=_type_ _mode_ _errors_ rename=(gfund=gfund_h)); run; /* Merging the What-If Simulations */ data what_if; merge budget out_p out_lo out_mid out_hi; by year; run; /* Printing the What-If Simulations */ proc print data=what_if; var year gfund p_gfund gfund_l gfund_m gfund_h; title2 'What-If Simulations'; run; goptions reset=symbol; /* Plotting the What-If Simulations */ proc gplot data=what_if; where year > 80; plot gfund*year=1 p_gfund*year=2 gfund_l*year=3 gfund_m*year=4 gfund_h*year=5 / overlay haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join l=1 color=black; symbol2 v=* font=swissb color=blue; symbol3 i=join v=L font=swissb l=33 color=green; symbol4 i=join v=M font=swissb l=33 color=red; symbol5 i=join v=H font=swissb l=33 color=gray; axis1 offset=(2,2)pct order=(81 to 89 by 1) label=none; axis2 order=(3000 to 5100 by 300) minor=(number=1) label=(a=-90 r=90 'GENERAL FUND'); legend1 label=none value=('Actual GFUND' 'Predicted GFUND' 'Low GFUND' 'Mid GFUND' 'High GFUND'); title 'General Fund'; title2 'Actual, What-If, and Predicted Values'; run; quit; /* Chapter 9 page 227 */ /* Creating Goal-Seeking Data Set, GOAL*/ data goal; input year gfund fed_rev; cards; 1990 5000 750 1990 5500 750 1990 6000 750 ; /* Goal-Seeking for GNP */ proc model model=bud_mod2 noprint; endogenous gnp; exogenous gfund fed_rev; solve gnp / data=goal out=goal_out; run; /* Printing the Solution Values */ proc print data=goal_out; var gfund gnp fed_rev; title2 'Goal-Seeking Values of GNP'; run; /* Chapter 10 pages 231-232 */ data homes; input year q pop yn cpi @@; y=yn/cpi; label q='New One-Family Houses Sold in Thousands' pop='U.S. Population in Millions' y='Real Personal Income in Billions' cpi='U.S. CPI 1982-1984 = 100'; cards; 70 485 205.052 715.6 .388 71 656 207.661 776.8 .405 72 718 209.896 839.6 .418 73 634 211.909 949.8 .444 74 519 213.854 1038.4 .493 75 549 215.973 1142.8 .538 76 646 218.035 1252.6 .569 77 819 220.239 1379.3 .606 78 817 222.585 1551.2 .652 79 709 225.055 1729.3 .726 80 545 227.719 1918.0 .824 81 436 229.945 2127.6 .909 82 412 232.171 2261.4 .965 83 623 234.296 2428.1 .996 84 639 236.343 2668.6 1.039 85 688 238.466 2838.7 1.076 86 750 240.658 3013.3 1.096 87 671 242.820 3194.7 1.136 88 676 245.051 3479.2 1.183 89 650 247.350 3725.5 1.240 90 536 249.975 3945.8 1.307 ; proc print data=homes (obs=5) label; var year q y pop; title 'New Homes Example'; title2 'First Five Observations HOMES Data'; run; goptions reset=symbol; proc gplot data=homes; plot q*year=1 / hminor=1 vminor=1 haxis=axis1 vaxis=axis2; symbol1 i=join v=Q font=swissb l=1; axis1 offset=(2,2)pct order=70 to 90 by 2; axis2 label=(a=-90 r=90 'QUANTITY SOLD'); title 'New One-Family Houses Sold in Thousands'; title2 'in Thousands'; run; quit; /* Chapter 10 page 234 */ proc model data=homes outmodel=home_mod; parms a b c d; q = a + b*y + c*lag(y) + d*pop; %ar(ar_q,1,q) endo q; exo y pop; id year; fit q / dw out=hom_out outactual; run; /* Chapter 10 page 236 */ proc model data=hom_out model=home_mod; solve q / simulate dynamic stats theil out=hom_sim1(rename=(q=q_sim_d)); run; /* Chapter 10 page 237 */ proc model data=hom_out model=home_mod; solve q / simulate static stats theil outlags out=hom_sim2(drop=_type_ _mode_ _lag_ _errors_ rename=(q=q_sim_s)); run; /* Chapter 10 page 239 */ /* Simulating the Model */ proc model data=hom_out model=home_mod noprint; solve q / simulate start=6 outlags out=hom_sim3(rename=(q=q_sim_sd)); run; /* Printing Simulated Values */ proc print data=hom_sim3; var year q_sim_sd; title2 'Mixed Static and Dynamic Simulation'; run; /* Chapter 10 pages 240-241 */ data homes_p; merge homes hom_sim1 hom_sim2 hom_sim3; by year; run; proc print data=homes_p; var year q q_sim_d q_sim_s q_sim_sd; title2 'Actual Values'; title3 'Dynamic and Static Simulation Values'; title4 'and Mixed Simulation Values'; run; goptions reset=symbol; proc gplot data=homes_p; plot q*year=1 q_sim_d*year=2 q_sim_s*year=3 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join l=1 color=black; symbol2 v=D font=swissb color=blue; symbol3 v=S font=swissb color=green; axis1 offset=(2,2)pct order=70 to 90 by 2; axis2 order=400 to 900 by 100 label=(a=-90 r=90 'QUANTITY SOLD'); legend1 label=none value=('New One-Family Homes' 'Dynamic Simulation' 'Static Simulation'); title 'Dynamic and Static Simulation'; title2 'New One-Family Homes Sold in Thousands'; run; quit; /* Chapter 10 page 243 */ proc autoreg data=mcon outest=mcn_est; model c=c_1 di / method=yw nlag=1 lagdep=c_1; run; /* Chapter 10 pages 245-247 */ proc simlin est=mcn_est data=mcon type=ols interim=2 total; endogenous c; exogenous di; lagged c_1 c 1; output out=mcn_out predicted=c_pred; run; /* Printing Simulated Values */ proc print data=mcn_out (obs=12) label; var date c_pred c c_1 di; title2 'First Twelve Simulation Values'; run; goptions reset=symbol; /* Plotting Actual and Simulated Values */ proc gplot data=mcn_out; plot c*date=1 c_pred*date=2 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 v=none i=join l=1 color=black; symbol2 v=none i=join l=3 color=blue; axis1 label=none offset=(0,2)pct minor=(n=3) order=('01JAN82'd to '01JAN91'd by year); axis2 label=(a=-90 r=90 'CONSUMPTION'); legend1 label=none value=('Actual Consumption' 'Simulated Consumption'); title 'Actual and Simulated Consumption'; run; quit; /* Chapter 10 pages 248-249 */ /* Dropping First Six Observations */ data mcon1; set mcon; if date < '01mar83'd then delete; run; /* Simulating the Model */ proc simlin est=mcn_est data=mcon1 type=ols; endogenous c; exogenous di; lagged c_1 c 1; output out=mcn_out1 predicted=c_pred1; run; /* Printing Simulated Values */ proc print data=mcn_out1 (obs=8) label; var date c_pred1 c c_1 di; title 'Monthly Consumption Function Example'; title2 'Simulation Starting March 1983'; title3 'First Eight Simulation Values'; run; /* Chapter 11 page 253 */ proc print data=klein (obs=5) label; var year c p wp i k x wg g t; title 'KLEIN Model 1 Example'; title2 'First Five Observations KLEIN Data'; run; /* Chapter 11 page 254 */ /* Invoking PROC MODEL */ proc model data=klein outmodel=kl_mod noprint; parms a1-a4 b1-b4 c1-c4; /* Model Equations */ c=a1+a2*p+a3*lag(p)+a4*wt; i=b1+b2*p+b3*lag(p)+b4*lag(k); wp=c1+c2*x+c3*lag(x)+c4*time; /* Identities */ x=c+i+g; p=x-wp-t; k=lag(k)+i; wt=wp+wg; /* Endogenous and Exogenous Variables */ endo c i wp x p wt k; exo p_1 k_1 x_1 time t g wg; /* Variable Included in Output Data Set */ id year; /* Estimating the Model */ fit c i wp / 3sls; run; /* Chapter 11 page 255 */ /* Simulating the Model */ proc model data=klein model=kl_mod; solve c i wp / simulate start=2 stats theil out=kl_out1(rename=(c=sim_c1 i=sim_i1 wp=sim_wp1)); run; /* Chapter 11 pages 256-257 */ /* Merging Data */ data klein_p; merge klein kl_out1; by year; label sim_c1 = 'Simulated C' sim_i1 = 'Simulated I' sim_wp1 = 'Simulated WP'; run; /* Printing Simulated Values */ proc print data=klein_p label; var year c sim_c1 i sim_i1 wp sim_wp1; title 'KLEIN Model 1 Example'; title2 'Actual and Simulated Values'; run; goptions reset=symbol; /* Plotting Simulated and Actual Values */ proc gplot data=klein_p; plot c*year=1 sim_c1*year=2 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join l=1 color=black; symbol1 v=C font=swissb color=blue; axis1 label=none offset=(2,2)pct order=1921 to 1941 by 2; axis2 label=(a=-90 r=90 'CONSUMPTION'); legend1 label=none value=('Actual Consumption' 'Simulated Consumption'); title 'Actual and Simulated Consumption'; run; quit; /* Chapter 11 page 260 */ data kl_sim; input year sim_x sim_p @@; cards; 1929 67.0 21.7 1930 69.1 24.6 1931 72.0 26.1 1932 74.9 27.7 1933 77.9 29.3 1934 81.1 31.1 1935 84.3 32.9 1936 87.7 34.9 1937 91.3 36.9 1938 94.9 39.1 1939 98.7 41.5 1940 102.7 44.0 1941 106.8 46.6 ; data klein_p1; merge klein kl_sim; by year; run; proc print data=klein_p1 (firstobs=10 obs=15); var year x sim_x p sim_p; title2 'Tenth-Fifteenth Observations'; title3 'of KLEIN_P1 Data'; run; proc plot data=klein_p1 vpct=60; plot x*year='A' sim_x*year='H' / overlay; title2 'Actual and What-If Simulation Values'; title3 'Total Output of Private Industry'; run; proc plot data=klein_p1 vpct=60; plot p*year='A' sim_p*year='H' / overlay; title2 'Actual and What-If Simulation Values'; title3 'Profits'; run; /* Chapter 11 pages 262-263 */ /* Updating the KLEIN Data Set */ data klein1; update klein kl_sim(rename=(sim_x=x sim_p=p)); by year; run; /* Performing the What-If Simulation */ proc model data=klein1 model=kl_mod noprint; solve c i wp / simulate start=2 out=kl_out2(rename=(c=sim_c2 i=sim_i2 wp=sim_wp2)); run; /* Merging Data */ data klein_p2; merge klein kl_out2; by year; label sim_c2 = 'What-If Simulated C' sim_i2 = 'What-If Simulated I' sim_wp2 = 'What-If Simulated WP'; run; /* Printing Simulated Values */ proc print data=klein_p2 (firstobs=10) label; var year c sim_c2 i sim_i2 wp sim_wp2; title 'KLEIN Model 1 Example'; title2 'What-If Simulated Values'; title3; run; goptions reset=symbol; /* Plotting Simulated Values */ proc gplot data=klein_p2; plot c*year=1 sim_c2*year=2 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join l=1 color=black; symbol1 v=C font=swissb color=blue; axis1 label=none offset=(2,2)pct order=1921 to 1941 by 2; axis2 label=(a=-90 r=90 'CONSUMPTION'); legend1 label=none value=('Actual Consumption' 'What-If Consumption'); title 'Actual and What-If Consumption'; run; quit; /* Chapter 11 pages 265-266 */ /* Performing Goal Seeking */ proc model data=klein1 model=kl_mod; solve g satisfy=x / simulate start=2 out=kl_out3(rename=(g=sim_g)); run; /* Merging Data */ data klein_p3; merge klein kl_out3; by year; label sim_g = 'Goal-Seeking G'; run; /* Printing Goal Seeking Values */ proc print data=klein_p3 (firstobs=10) label; var year g sim_g; title2 'Actual and Goal-Seeking Values'; run; /* Chapter 11 pages 267-268 */ /* Creating Values for X and Y */ data sd; q = .; p = .; do y=50 to 160 by 10; x = 100; id='D'; output; end; do x=60 to 120 by 10; y = 125; id='S'; output; end; run; /* Simulating the Model */ proc model data=sd noprint; q = 10000 - 11*p + 10*x; p = 40 + 0.07*q - .5*y; endo q p; exo x y; solve q p / simulate out=sd_sim; id id; run; /* Printing the Simulated Values */ proc print data=sd_sim; var q p x y; title 'General Supply and Demand Model Example'; run; proc plot data=sd_sim vpct=60; plot p*q=id; title2 'Plotting Supply and Demand Schedules'; run; /* Chapter 11 pages 271-272 */ data cost; cost = .; revenue = .; profit = .; do quantity=0 to 28000 by 1000; output; end; run; proc model data=cost noprint; /* Defining the cost function */ worker = quantity/100; if worker lt 20 then supervis = 0; else supervis = worker/20; if supervis lt 5 then manager = 0; else manager = supervis/5; machine1 = quantity/500; if machine1 lt 20 then machine2=0; else machine2 = quantity/10000; if quantity lt 2000 then cost = 150000 + 18000*worker + 35000*supervis + 50000*manager + 12000*machine1; if 2000 le quantity lt 10000 then cost = 200000 + 18000*worker + 35000*supervis + 50000*manager + 12000*machine1; if quantity ge 10000 then cost = 250000 + 18000*worker + 35000*supervis + 50000*manager + 12000*machine1 + 75000*machine2; /* Defining REVENUE, TAX, NET_REV, and PROFIT */ revenue = 550*quantity - .0075*quantity**2; tax = 100000 + 100*quantity; net_rev = revenue - tax; profit = net_rev - cost; /* Solving the Model */ endo cost revenue tax net_rev profit; exo quantity; solve revenue tax net_rev cost profit / simulate out=cst_sim; run; /* Printing Solution Values */ proc print data=cst_sim; var quantity revenue tax net_rev cost profit; title 'Profit Model Example'; title2 'Cost, Revenue, and Profit Simulation'; run; /* Chapter 11 page 273 */ proc plot data=cst_sim vpct=60; plot cost*quantity = 'c' net_rev*quantity = 'r' / overlay; title2 'Cost and Net Revenue versus Quantity'; run; proc plot data=cst_sim vpct=60; plot profit*quantity = '*'; title2 'Profit versus Quantity'; run; /* Chapter 12 page 278 */ proc print data=pc label; var yr percent; title 'Logistic Curve Example'; title2 'PC Data'; run; /* Chapter 12 page 279 */ proc model data=pc model=pc_mod; solve percent / simulate stats theil out=pc_sim1(rename=(percent=sim_p1)); run; /* Chapter 12 page 281 */ /* Merging Data */ data pc_p; merge pc pc_sim1; by yr; label sim_p1 = 'Simulated PERCENT'; run; /* Printing Actual and Simulated Values */ proc print data=pc_p label; var yr percent sim_p1; title 'Logistic Curve Example'; title2 'PC_SIM1 Data'; run; goptions reset=symbol; /* Plotting Actual and Simulated Values */ proc gplot data=pc_p; plot percent*yr=1 sim_p1*yr=2 / overlay hminor=0 vminor=3 haxis=axis1 vaxis=axis2; symbol1 v=A font=swissb color=black; symbol2 i=join font=swissb l=3 color=blue; axis1 offset=(3) order=(81 to 88 by 1); axis2 label=(angle=90 'Percent of Schools') order=(0 to 100 by 10); title 'Personal Computer Use'; title2 'Actual and Simulated'; run; quit; /* Chapter 12 page 283 */ /* Fitting the Model */ proc model data=pc outmodel=pc_mod; parms a b c; percent = a/(1 + exp(b + c*year)); fit percent start=(a=100 b=100 10 c=-.5 -1 -1.5) / converge=.0001 method=marquardt outs=pc_s noprint; id yr; run; /* Performing Monte Carlo Simulations */ proc model data=pc model=pc_mod noprint; solve percent / sdata=pc_s random=100 seed=174596 out=pc_sim2(drop=_type_ _mode_ _errors_ rename=(percent=sim_p2)); run; /* Printing Simulated Values */ proc print data=pc_sim2 (obs=24) label; var _rep_ yr sim_p2; title2 'Monte Carlo Simulations, Partial Listing'; run; /* Chapter 12 pages 284-285 */ /* Sorting Data */ proc sort data=pc_sim2 out=pc_sim3; by yr; run; /* Calculating Summary Statistics */ proc means data=pc_sim3 noprint; var sim_p2; by yr; output out=pc_sim4 mean=mean std=std stderr=stderr; run; /* Merging Data */ data pc2; merge pc pc_sim1 pc_sim4; by yr; run; /* Printing Summary Statistics */ proc print data=pc2; var yr percent sim_p1 mean std stderr; title2 'Summary Statistics'; title3 'of Monte Carlo Simulations'; run; /* Chapter 12 page 286 */ proc univariate data=pc_sim3 normal; var sim_p2; by yr; output out=pc_sim5 p5=p5 mean=mean p95=p95; title 'Logistic Curve Example'; title2 'Testing for Normality'; title3; run; /* Chapter 12 pages 288-289 */ /* Merging Data */ data pc3; merge pc_sim5 pc; by yr; run; /* Printing Data */ proc print data=pc3; var yr p5 mean percent p95; title 'Logistic Curve Example'; title2 'Actual Values, Mean, and Percentiles'; run; goptions reset=symbol; /* Plotting Data */ proc gplot data=pc3; plot p5*year=1 percent*year=2 p95*year=3 / overlay haxis=axis1 hminor=1 vaxis=axis2 vminor=1 legend=legend1; symbol1 v=L font=swissb color=black; symbol2 i=join l=1 color=blue; symbol3 v=H font=swissb color=green; axis1 label=('YEAR in 1980s') offset=(2,2)pct order=1 to 8; axis2 label=(a=-90 r=90 'PERCENT'); legend1 label=none value=('Fifth Percentile' 'Actual PC Dispersion' 'Ninety-Fifth Percentile'); title 'PC Dispersion with Percentiles 5 and 95; run; /* Chapter 12 page 290 */ /* Creating the Input Data Set, PC_GOAL */ data pc_goal; input yr percent @@; year=yr-80; cards; 82.5 50 ; /* Performing Goal-Seeking Simulation */ proc model data=sim_pc model=pc_mod noprint; solve year satisfy=percent / converge=1E-12 out=pc_goal1(rename= (percent=pc_gs)); run; /* Printing Solution Values */ proc print data=pc_goal1; var yr pc_gs; title 'Logistic Curve Example'; title2 'Goal-Seeking Solutions'; run; /* Chapter 12 page 291 */ /* Creating the CUBIC Data Set */ data cubic; do q=0 to 100 by 2; cost=10000 + 20*q - .35*q**2 + .0025*q**3; output; end; run; /* Plotting the Cost Function */ proc plot data=cubic vpct=60; plot cost*q; title 'Cubic Cost Function Example'; title2 'Cost versus Quantity'; run; /* Chapter 12 pages 292-293 */ /* Creating the CUB_COST Data Set */ data cub_cost; input q cost @@; cards; 20 10250 60 10500 90 10750 100 11000 ; /* Performing Goal-Seeking */ proc model data=cub_cost; cost = 10000 + 20*q - .35*q**2 + .0025*q**3; endo q; exo cost; solve q satisfy=cost / simulate out=cub_out noprint; run; /* Listing Solution Values */ proc print data=cub_out; var cost q; title 'Cubic Cost Function Example'; title2 'Simulations of Quantity Given Cost'; run; /* Chapter 12 pages 294-295 */ /* Creating the PV Data Set */ data pv; do x=150000,175000; do r=35000,37500; do i=.05,.06; do s=50000,75000; pv=.; output; end; end; end; end; label pv='Present Value' x='Current Period Cost' r='Annual Return' i='Interest Rate' s='Salvage Value'; run; /* Performing the Simulation */ proc model data=pv; pv = -x + r*(1/(1+i) + 1/((1+i)**2) + 1/((1+i)**3) + 1/((1+i)**4)) + s*1/((1+i)**4); endo pv; exo x r i s; solve pv / simulate out=pv_out noprint; run; /* Listing Solution Values */ proc print data=pv_out label; var pv x r i s; title 'Present Value Example'; title2 'Solution Values'; run; /* Chapter 12 page 296 */ /* Creating the IRR Data Set */ data irr; input pv i x r s; label pv='Present Value' i='Interest Rate' x='Current Period Cost' r='Annual Return' s='Salvage Value'; cards; 125000 . 45000 40000 35000 125000 . 45000 40000 40000 125000 . 45000 50000 35000 125000 . 45000 50000 40000 125000 . 50000 40000 35000 125000 . 50000 40000 40000 125000 . 50000 50000 35000 125000 . 50000 50000 40000 ; /* Solving the Model */ proc model; pv = -x + r*(1/(1+i) + 1/((1+i)**2) + 1/((1+i)**3) + 1/((1+i)**4)) + s*1/((1+i)**4); endo i; exo pv x r s; solve i satisfy=pv / simulate data=irr out=irr_out noprint; run; /* Printing the Solutions */ proc print data=irr_out label; var pv x r i s; title 'Internal Rates of Return Example'; title2 'Solution Values'; run; /* Chapter 12 page 298 */ /* Creating the GROW Data Set */ data grow; input y s f g v m; label y=Yearly Income s=Monthly Sales f=Fixed Costs g=Growth Rate v=Variable Cost Percentage m=Months; cards; 1200000 150000 35000 .05 .40 12 ; /* Solving the Model */ proc model data=grow; var y s f g v m; ys=s*(1+(1+g)**1 + (1+g)**2 + (1+g)**3 +(1+g)**4 + (1+g)**5 + (1+g)**6 +(1+g)**7 + (1+g)**8 + (1+g)**9 +(1+g)**10 + (1+g)**11); c=v*ys+f*m; y=ys-c; solve y satisfy=y / out=grw_out; run; /* Printing the Output Data Set */ proc print data=grw_out label; var y s f g v m; title 'Income Growth Model Example'; title2 'Yearly Income Simulation'; run; /* Chapter 13 pages 304-305 */ data budget; input year gfundn gnpn fed_revn pop cpi @@; gfund = gfundn / cpi; gnp = gnpn / cpi; fed_rev = fed_revn / cpi; label gfund = 'Real General Fund in Millions' gnp = 'Real US GNP in Billions' fed_rev = 'Real Federal IRS Collections in Billions' pop = 'NC Population in Thousands' cpi = 'US CPI 82-84 = 100'; title 'General Fund Revenues Example'; cards; 73 1214.0 1359.3 237.8 5382 .444 74 1358.0 1472.8 269.0 5461 .493 75 1451.0 1598.4 293.8 5535 .538 76 1572.0 1782.8 302.5 5593 .569 77 1870.0 1990.5 358.1 5668 .606 78 2060.0 2249.7 399.8 5739 .652 79 2337.0 2508.2 460.4 5802 .726 80 2639.0 2732.0 519.4 5882 .824 81 2846.0 3052.6 606.8 5957 .909 82 3078.0 3166.0 632.2 6018 .965 83 3279.0 3405.7 627.2 6078 .996 84 3814.0 3772.2 680.5 6167 1.039 85 4337.0 4010.3 742.9 6258 1.076 86 4695.0 4235.0 782.3 6327 1.096 87 5181.0 4524.3 886.3 6409 1.136 88 5552.0 4880.6 935.1 6489 1.183 89 5928.5 5200.8 1013.5 6571 1.240 ; /* Chapter 13 page 307 */ /* Fitting the Model */ proc autoreg data=budget noprint; model gfund = gnp pop / nlag=1 method=ml; output out=bud_f alphacli=.05 p=p lcl=l ucl=u; run; /* Calculating Confidence Interval Width */ data bud_fp; set bud_f; width=u-l; run; /* Printing Confidence Limits */ proc print data=bud_fp; var year l gfund p u width; title2 'Actual and Predicted Values'; title3 'with 95% Confidence Limits'; run; /* Chapter 13 page 308 */ goptions reset=symbol; proc gplot data=bud_fp; plot gfund*year=1 p*year=2 l*year=3 u*year=4 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 v=A font=swissb color=black; symbol2 i=join font=swissb l=1 color=blue; symbol3 i=join font=swissb l=20 color=green; symbol4 i=join font=swissb l=20 color=red; axis1 offset=(2,2)pct order=73 to 89 by 2; axis2 order=2000 to 5500 by 500 label=(a=-90 r=90 'GENERAL FUND'); legend1 label=none value=('Actual General Fund' 'Predicted General Fund' 'Lower 95% Confidence Limit' 'Upper 95% Confidence Limit'); title 'General Fund Revenues'; title2 'Actual, Predicted, and 95% CI'; run; quit; /* Chapter 13 pages 310-311 */ /* Creating POP Values for Forecasting */ data pop; do year=90 to 95; pop_base=6571*(1+.012)**(year-89); pop_low =6571*(1+.006)**(year-89); pop_grow=6571*(1+.018)**(year-89); gnp=(5200.8/1.240)*(1+.019)**(year-89); output; end; run; /* Creating BUDGETB Data Set */ /* for Base Scenario Forecasting */ data budgetb; set budget pop(rename=(pop_base=pop)); drop pop_low pop_grow; run; /* Creating BUD_P Data Set for Plotting */ data bud_p; set budget pop; run; /* Printing Observations */ proc print data=bud_p (firstobs=15) label; var year gnp pop pop_low pop_base pop_grow; title2 'Input Values for Forecasting'; title3 'GNP and Population'; run; goptions reset=symbol; /* Plotting Scenario Values */ proc gplot data=bud_p; where year > 86; plot pop*year=1 pop_base*year=2 pop_low*year=3 pop_grow*year=4 / overlay hminor=1 vminor=0 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join v=A font=swissb l=1 color=black; symbol2 i=join v=B font=swissb l=3 color=blue; symbol3 i=join v=L font=swissb l=3 color=green; symbol4 i=join v=G font=swissb l=3 color=red; axis1 offset=(2,2)pct order=87 to 95 label=none; axis2 order=6300 to 7400 by 100 label=(a=-90 r=90 'NC POPULATION'); legend1 label=none value=('Actual Population' 'Base Scenario Population' 'Low Scenario Population' 'Growth Scenario Population'); title 'N.C. Population 1987-1995'; title2 'Actual, Base, Low, and Growth'; run; quit; /* Chapter 13 page 313 */ /* Predicting Base Scenario GFUND Values */ proc autoreg data=budgetb noprint; model gfund = gnp pop / nlag=1 method=ml; output out=budb_out alphacli=.05 p=f lcl=l ucl=u; run; /* Deleting Unneeded Values */ data budgetbp; set budb_out; if year<90 then l=.; if year<90 then u=.; if year<90 then f=.; width=u-l; run; /* Printing Actual and Scenario Values of GFUND */ proc print data=budgetbp (firstobs=15) label; var year l gfund f u width; title2 'GFUND Forecast and Confidence Limits'; title3; run; goptions reset=symbol; /* Plotting the Values */ proc gplot data=budgetbp; where year > 86; plot gfund*year=1 f*year=2 l*year=3 u*year=4 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join v=A font=swissb l=1 color=black; symbol2 i=join v=F font=swissb l=3 color=blue; symbol3 i=join v=L font=swissb l=3 color=green; symbol4 i=join v=U font=swissb l=3 color=red; axis1 offset=(2,2)pct order=87 to 95 label=none; axis2 order=4200 to 6300 by 300 label=(a=-90 r=90 'General Fund'); legend1 label=none value=('Actual GFUND' 'Forecast GFUND' 'Lower 95% Confidence Limit' 'Upper 95% Confidence Limit'); title 'N.C. General Fund 1987-1995'; title2 'Base Scenario'; run; quit; /* Chapter 13 page 315 */ /* Predicting GFUND Values */ proc autoreg data=budgetl noprint; model gfund = gnp pop / nlag=1 method=ml; output out=budl_out p=gl; run; proc autoreg data=budgetg noprint; model gfund = gnp pop / nlag=1 method=ml; output out=budg_out p=gg; run; /* Merging Data Sets */ data budgetp; merge budget budl_out budgetbp budg_out; by year; if year<90 then gl=.; if year<90 then f=.; if year<90 then gg=.; run; /* Printing Actual and Scenario Values of GFUND */ proc print data=budgetp (firstobs=15) label; var year gfund gl f gg; title2 'GFUND Forecasts'; title3 'Low, Base, and Growth POP Scenarios'; run; /* Chapter 13 page 316 */ goptions reset=symbol; proc gplot data=budgetp; where year > 86; plot gfund*year=1 gl*year=2 f*year=3 gg*year=4 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join v=A font=swissb l=1 color=black; symbol2 i=join v=L font=swissb l=3 color=blue; symbol3 i=join v=B font=swissb l=3 color=green; symbol4 i=join v=G font=swissb l=3 color=red; axis1 offset=(2,2)pct order=87 to 95 by 2 label=none; axis2 order=4500 to 6000 by 300 label=(a=-90 r=90 'General Fund'); legend1 label=none value=('Actual GFUND' 'Low POP Scenario GFUND' 'Base POP Scenario GFUND' 'Growth POP Scenario GFUND'); title 'N.C. General Fund 1987-1995'; title2 'Actual, Base, Low, and Growth'; run; quit; /* Chapter 14 page 321 */ proc model data=mcon outmodel=mc_mod; parms b0 w b1; c = b0 + w*lag(c) + b1*di; %ar(ar_c,1,c) endo c; exo di; fit c start=(ar_c_l1 -.5 .5); id date; run; /* Chapter 14 pages 322-324 */ data mc_grow; /* Growth Rate of Disposable Income */ dig= (3037.49/3006.51)-1; /* DO Loop */ do i=1 to 12; retain date '01jun90'd; date=intnx('month',date,1); format date monyy.; /* Constant Growth Rate DI Values */ di_base= 3037.49*(((dig/12)*i)+1); /* Perturbed Growth Rate DI Values */ if i=1 then di_per=(3037.49*(((dig/12)*i)+1))+200; else di_per=di_base; output; end; run; data mcon2; set mcon mc_grow; run; /* Partial Listing of MCON2 Data Set */ proc print data=mcon2 (firstobs=82); var date c di di_base di_per; title2 'Actual and Extrapolated Values'; run; goptions reset=symbol; /* Plotting Constant DI Growth Case */ proc gplot data=mcon2; where date ge '01FEB89'd; plot di*date=1 di_base*date=2 / overlay hminor=2 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join font=swissb l=1 color=black; symbol2 i=join font=swissb l=3 color=blue; axis1 label=none offset=(2,2)pct; axis2 order=2900 to 3300 by 100 label=(a=-90 r=90 'DI $ Billions'); legend1 label=none value=('Actual Disposable Income' 'Extrapolated Disposable Income'); title 'Disposable Income FEB89-JUN91'; title2 'Base (or Constant Growth) Case'; run; /* Create Plot of Perturbed DI Growth Case */ proc gplot data=mcon2; where date ge '01FEB89'd; plot di*date=1 di_per*date=2 / overlay hminor=2 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join font=swissb l=1 color=black; symbol2 i=join font=swissb l=3 color=blue; axis1 label=none offset=(2,2)pct; axis2 order=2900 to 3300 by 100 label=(a=-90 r=90 'DI $ Billions'); legend1 label=none value=('Actual Disposable Income' 'Extrapolated Disposable Income'); title 'Disposable Income FEB89-JUN91'; title2 'Perturbed Case'; run; quit; /* Chapter 14 pages 326-327 */ /* Constant Growth Case */ data mc_base; set mcon2; if di=. then di=di_base; run; /* Perturbed Growth Case */ data mc_per; set mcon2; if di=. then di=di_per; run; /* Forecasting C */ proc model model=mc_mod noprint; /* Forecasting Constant Growth Case */ solve / forecast data=mc_base start=2 out=mc_outb(drop=_type_ _mode_ _errors_ rename=(c=fore_b)); /* Forecasting Perturbed Growth Case */ solve / forecast data=mc_per start=2 out=mc_outp(drop=_type_ _mode_ _errors_ rename=(c=fore_p)); run; /* Merging Data Sets */ data mc_outb1; merge mc_base mc_outb; by date; run; data mc_outp1; merge mc_perb mc_outp; by date; run; /* Printing Constant Growth Rate Case */ proc print data=mc_outb1 (firstobs=90); var date di c fore_b; title2 'Base Case Forecasts'; run; /* Printing Perturbed Growth Rate Case */ proc print data=mc_outp1 (firstobs=90); var date di c fore_p; title2 'Perturbed Case Forecasts'; run; /* Chapter 14 pages 328-329 */ /* Data for Comparison Variables */ data mc_comb; merge mc_outb1 mc_outp1; by date; /* Changes in Each Series */ fore_bd=fore_b-lag(fore_b); fore_pd=fore_p-lag(fore_p); /* Rates of Changes in Each Series */ fore_bd2=fore_bd-lag(fore_bd); fore_pd2=fore_pd-lag(fore_pd); /* Differences between the Series */ dif_pb=fore_p-fore_b; run; /* Printing the Comparison Variables */ proc print data=mc_comb (firstobs=92); var date fore_bd fore_pd fore_bd2 fore_pd2 dif_pb; title2 'Differences in Forecasts'; run; /* Creating COMBINE1 Data Set for Plotting */ data mc_comb1; merge mc_outb1 mc_outp1; if date le '01JUN90'd then fore_b=.; if date le '01JUN90'd then fore_p=.; run; goptions reset=symbol; /* Plotting the Series */ proc gplot data=mc_comb1; where date ge '01FEB89'd; plot c*date=1 fore_b*date=2 fore_p*date=3 / overlay hminor=2 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join font=swissb l=1 color=black; symbol2 v=B i=join font=swissb l=3 color=blue; symbol3 v=P i=join font=swissb l=3 color=green; axis1 label=none offset=(2,2)pct; axis2 label=(a=-90 r=90 'CONSUMPTION'); legend1 label=none value=('Actual Consumption' 'Consumption from Constant DI Growth' 'Consumption from Perturbed DI Growth'); title 'Consumption Expenditures FEB89-JUL91'; run; quit; /* Chapter 14 pages 331-332 */ /* Fitting the Keynesian Consumption Function */ proc model data=mcon outmodel=mcky_mod noprint; parms a b; c = a + b*di; %ar(ar_c,1,c) endo c; exo di; fit c start=(ar_c_l1 -.5 .5); id date; run; /* Forecasting C */ proc model model=mcky_mod noprint; /* Forecasting Constant Growth Case */ solve / forecast data=mc_base start=2 out=mc_outbk(drop=_type_ _mode_ _errors_ rename=(c=fore_b)); /* Forecasting Perturbed Growth Case */ solve / forecast data=mc_per start=2 out=mc_outpk(drop=_type_ _mode_ _errors_ rename=(c=fore_p)); run; /* Merging Data Sets */ data mc_combk; merge mc_base mc_outbk mc_outpk; by date; if date le '01JUN90'd then fore_b=.; if date le '01JUN90'd then fore_p=.; run; /* Printing Forecasts */ proc print data=mc_combk (firstobs=90); var date c fore_b fore_p; title2 'Keynesian Consumption Function Forecasts'; run; goptions reset=symbol; /* Plotting the Series */ proc gplot data=mc_combk; where date ge '01FEB89'd; plot c*date=1 fore_b*date=2 fore_p*date=3 / overlay hminor=2 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join font=swissb l=1 color=black; symbol2 v=B i=join font=swissb l=3 color=blue; symbol3 v=P i=join font=swissb l=3 color=green; axis1 label=none offset=(2,2)pct; axis2 label=(a=-90 r=90 'CONSUMPTION'); legend1 label=none value=('Actual Consumption' 'Consumption from Constant DI Growth' 'Consumption from Perturbed DI Growth'); title 'Keynesian Consumption Function'; title2 'Consumption Expenditures FEB89-JUL91'; run; quit; /* Chapter 14 page 334 */ /* Fitting the Model */ proc pdlreg data=almon; model cap_exp=appro(7,2,2,last) / nlag=2; output out=al_out alphaclm=.05 pm=p lclm=l uclm=u; run; /* Printing Predicted Values */ proc print data=al_out (firstobs=48); var date cap_exp p l u; title2 'Actual and Predicted Values'; title3 'with Confidence Limits'; run; /* Chapter 14 page 336 */ goptions reset=symbol; proc gplot data=al_out; where date ge '01APR65'd; plot cap_exp*date=1 p*date=2 l*date=3 u*date=4 / overlay hminor=2 vminor=1 haxis=axis1 vaxis=axis2; symbol1 v=A font=swissb color=black; symbol2 i=join font=swissb l=1 color=blue; symbol3 i=join font=swissb l=3 color=green; symbol4 i=join font=swissb l=3 color=red; axis1 label=none offset=(2,2)pct order='01apr65'd to '31dec67'd by qtr; axis2 label=(a=-90 r=90 'CAP_EXP') order=4000 to 6000 by 400; title 'Capital Expenditures'; title2 'with 95% Confidence Intervals'; run; quit; /* Chapter 14 pages 337-338 */ data al_time; set almon; do t=_n_; t2=t*t; output; end; run; /* Creating New Time Observations to Extrapolate APPRO */ data al_grow; do t=61 to 72; retain date '01oct67'd; date=intnx('qtr',date,1); format date yyq.; t2=t*t; appro=.; output; end; run; /* Combining Data Sets */ data al_grow1; set al_time al_grow; run; /* Extrapolating APPRO */ proc autoreg data=al_grow1 noprint; model appro=t t2; output out=al_out1 pm=approp; run; /* Eliminating Unneeded Observations */ data al_grow2; set al_out1; if date < '01jan68'd then approp=.; run; /* Plotting APPRO */ proc plot data=al_grow2 vpct=60; plot appro*date = 'A' approp*date = 'F' / overlay haxis='01oct54'd to '31dec70'd by year href='01jan68'd; title2 'Capital Appropriations 54Q4-70Q4'; title3 'Actual and Predicted'; run; /* Chapter 14 pages 339-430 */ data al_base; set al_grow2; if appro=. then appro=approp; run; proc print data=al_base (firstobs=56 obs=65); var date cap_exp appro approp; title2 'Base Scenario'; run; data al_per; set al_grow2; if date='01jan68'd then appro=approp+2000; if date>'01jan68'd then appro=approp; run; proc print data=al_per (firstobs=56 obs=65); var date cap_exp appro approp; title2 'Perturbed Scenario'; run; /* Chapter 14 pages 340-341 */ /* Forecasting Base Case */ proc pdlreg data=al_base noprint; model cap_exp=appro(7,2,2,last) / nlag=2; output out=al_outb alphaclm=.05 pm=f_base lclm=l_base uclm=u_base; run; /* Forecasting Perturbed Case */ proc pdlreg data=al_per noprint; model cap_exp=appro(7,2,2,last) / nlag=2; output out=al_outp alphaclm=.05 pm=f_per lclm=l_per uclm=u_per; run; /* Printing Values */ proc print data=al_outb (firstobs=57); var date cap_exp l_base f_base u_base; title2 'Base Scenario'; run; proc print data=al_outp (firstobs=57); var date cap_exp l_per f_per u_per; title2 'Perturbed Scenario'; run; /* Chapter 14 page 342 */ data al_comb; merge al_outb al_outp; by date; if date le '01DEC67'd then delete; diff=f_per-f_base; run; proc print data=al_comb; var date f_per f_base diff; title2 'Comparing Forecasts'; run; /* Chapter 14 page 343 */ goptions reset=symbol; proc gplot data=al_comb; where date ge '01DEC67'd; plot diff*date=1 / overlay hminor=2 vminor=1 haxis=axis1 vaxis=axis2; symbol1 v=D i=join font=swissb l=1; axis1 label=none offset=(2,2)pct order='01jan68'd to '01oct70'd by qtr; axis2 label=none order=-50 to 350 by 50; title 'Difference of Forecasts'; title2 'Capital Expenditures'; run; quit; /* Chapter 15 page 348 */ proc model data=klein outmodel=kl_mod; parms a1-a4 b1-b4 c1-c4; c=a1+a2*p+a3*lag(p)+a4*wt; i=b1+b2*p+b3*lag(p)+b4*lag(k); wp=c1+c2*x+c3*lag(x)+c4*time; x=c+i+g; p=x-wp-t; k=lag(k)+i; wt=wp+wg; endo c i wp x p wt k; exo p_1 k_1 x_1 time t g wg; id year; fit c i wp / 3sls; instruments p_1 k_1 x_1 time t g wg; run; /* Chapter 15 page 350 */ data kl_fore; /* Creating Extrapolated Input Values */ do year=1942 to 1946; time=year-1919; time1=year-1941; /* Base Scenario Growth Rates, */ /* Growth Rate Raised to Appropriate */ /* Power Times 1941 Value */ wg_b= 8.5*(1.04874)**time1; g_b =13.8*(1.26265)**time1; t_b =11.6*(1.11603)**time1; /* War Scenario Growth Rates */ wg_w= 8.5*(1.15)**time1; g_w =13.8*(1.40)**time1; t_w =11.6*(1.20)**time1; output; end; label wg_b = 'Government Wages Base Scenario' g_b = 'Government Goods Base Scenario' t_b = 'Government Taxes Base Scenario' wg_w = 'Government Wages War Scenario' g_w = 'Government Goods War Scenario' t_w = 'Government Taxes War Scenario'; run; proc print data=kl_fore label; var year wg_b g_b t_b wg_w g_w t_w; title 'KLEIN Model 1 Example'; title2 'Extrapolated Data for Forecasting'; run; /* Chapter 15 page 351 */ /* Concatenating Data Sets */ data klein_p4; set klein kl_fore; run; goptions reset=symbol; /* Plotting Actual and Extrapolated Values */ proc gplot data=klein_p4; where year ge 1932; plot wg*year=1 wg_b*year=2 wg_w*year=3 / overlay hminor=1 vminor=1 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join font=swissb l=1 color=black; symbol2 v=B i=join font=swissb l=3 color=blue; symbol3 v=W i=join font=swissb l=3 color=green; axis1 label=none offset=(2,2)pct order=1932 to 1946 by 2; axis2 label=none order=4 to 18 by 2; legend1 label=none value=('Actual Government Wages' 'Base Scenario Wages' 'War Scenario Wages'); title 'Government Wages 1932-1946'; title2 'Actual and Extrapolated'; run; quit; /* Chapter 15 pages 353-354 */ data kl_base (drop=wg_b g_b t_b wg_w g_w t_w); set kleinp_4; if wg=. then wg=wg_b; if g=. then g=g_b; if t=. then t=t_b; run; proc print data=kl_base (firstobs=22); var year wg t g; title 'KLEIN Model 1 Example'; title2 'Partial Listing of Base Case Data'; run; data kl_war (drop=wg_b g_b t_b wg_w g_w t_w); set klein6; if wg=. then wg=wg_w; if g=. then g=g_w; if t=. then t=t_w; run; proc print data=kl_war (firstobs=22); var year wg t g; title 'KLEIN Model 1 Example'; title2 'Partial Listing of Wartime Data'; run; /* Chapter 15 pages 355-356 */ /* Invoking PROC MODEL */ proc model model=kl_mod noprint; /* Forecasting Base Scenario */ solve / forecast data=kl_base start=3 out=kl_outb(rename=(c=c_b i=i_b wp=wp_b)); run; /* Forecasting War Scenario */ solve / forecast data=kl_war start=3 out=kl_outw(rename=(c=c_w i=i_w wp=wp_w)); run; /* Printing Base Scenario Forecasted Values */ proc print data=kl_outb (firstobs=23) label; var year c_b i_b wp_b; label c_b='Consumption Base Scenario' i_b='Investment Base Scenario' wp_b='Private Wages Base Scenario'; title2 'Base Case Scenario Forecasts'; run; \pg /* Printing Wartime Scenario Forecasted Values */ proc print data=kl_outw (firstobs=23) label; var year c_w i_w wp_w; label c_w='Consumption Wartime Scenario' i_w='Investment Wartime Scenario' wp_w='Private Wages Wartime Scenario'; title2 'Wartime Scenario Forecasts'; run; /* Chapter 15 page 357 */ /* Merging Data Sets */ data kleinp_5; merge klein kl_outb kl_outw; by year; array miss{6} c_b i_b wp_b c_w i_w wp_w; do j=1 to 6 while (year le 1941); miss{j}=.; end; run; goptions reset=symbol; /* Plotting Forecasts */ proc gplot data=kleinp_5; where year ge 1936; plot c*year=1 c_b*year=2 c_w*year=3 / overlay hminor=1 vminor=2 haxis=axis1 vaxis=axis2 legend=legend1; symbol1 i=join font=swissb l=1 color=black; symbol2 v=B i=join font=swissb l=3 color=blue; symbol3 v=W i=join font=swissb l=3 color=green; axis1 label=none offset=(2,2)pct order=1936 to 1946 by 2; axis2 label=(a=-90 r=90 'CONSUMPTION') order=45 to 180 by 15; legend1 label=none value=('Actual Consumption' 'Base Scenario Consumption' 'War Scenario Consumption'); title 'Consumption 1936-1946'; title2 'Actual and Forecasted'; run; quit; /* Chapter 15 pages 361-362 */ data energy_e; input exp q pi pop vam land elec id $ @@; /* Energy Expenditures / Energy Consumption = Price */ p=exp/q; label exp='Energy Expenditures' q='Energy Consumption' p='Energy Price' pi='Personal Disposable Income' pop='Population' vam='Value Added in Manufacturing' land='Land Area in Square Miles' elec='Electricity Generation' id='State Name'; cards; 7284 1614 10993 4103 18652 50767 67.5 AL 5475 757 19559 3232 22349 4872 36.4 CT 1049 174 18397 613 1525 63 0.5 DC 1223 230 14137 660 3866 1932 9.0 DE 17750 2929 14144 12338 27574 54153 124.1 FL 10911 2038 12925 6339 33708 58056 82.4 GA 19665 3577 15103 11613 63350 55645 123.3 IL 11052 2478 12638 5559 39279 35932 84.0 IN 6674 1401 11088 3726 18092 39669 76.4 KY 8915 1346 17690 5890 35770 7824 34.7 MA 6941 1240 16491 4626 14020 9837 40.4 MD 2204 372 13068 1206 5271 30995 9.5 ME 15199 2753 13958 9240 60259 56954 88.9 MI 4394 938 9560 2620 10503 47233 25.1 MS 10841 1947 12212 6489 47007 48843 78.4 NC 1687 243 17201 1085 8189 8993 7.0 NH 13991 2286 18998 7718 42527 7468 40.2 NJ 23422 3586 16269 17909 80033 47377 124.7 NY 19047 3785 13261 10865 71707 41004 124.0 OH 18889 3601 13881 11998 57605 44888 152.9 PA 1436 216 14352 993 4788 1055 0.8 RI 5825 1143 11098 3465 19112 30203 65.2 SC 8558 1714 12228 4898 27050 41155 60.0 TN 9763 1840 15010 6013 26857 39704 45.2 VA 902 129 13126 558 2543 9273 5.0 VT 7516 1392 13129 4832 31653 54426 45.0 WI 3160 778 10279 1876 5404 24119 81.3 WV ; proc print data=energy_e (obs=5); var id q exp p pi pop vam land elec; title 'ENERGY Model Example'; title2 'ENERGY_E Data'; run; proc model data=energy_e outmodel=en_mod; parms d0-d2 s0-s2; endo q p; exo pi pop vam land elec; eq.demand=d0+d1*p+d2*pop-q; eq.supply=s0+s1*p+s2*elec-q; id id; fit demand supply / 2sls; instruments pi pop vam land; run; /* Chapter 15 page 364 */ proc model model=en_mod; solve p q / data=energy_e stats theil out=en_oute(drop=_type_ _mode_ _errors_ rename=(p=price_e q=quant_e)); run; /* Chapter 15 page 365 */ /* Merging Data Sets for Plotting */ data en_outep; merge energy_e en_oute; by id; label price_e='Predicted Price' quant_e='Predicted Quantity'; run; /* Plotting Actual versus Predicted Values */ proc plot data=en_outep vpct=60; plot p*price_e='*'; plot q*quant_e='*'; title 'ENERGY Model Example'; title2 'ENERGY_E Data'; title3 'Actual and Predicted Values'; run; /* Chapter 15 pages 367-369 */ data energy_w; input exp q pi pop vam land elec id $ @@; p=exp/q; label exp='Energy Expenditures' q='Energy Consumption' p='Energy Price' pi='Personal Disposable Income' pop='Population' vam='Value Added in Manufacturing' land='Land Area in Square Miles' elec='Electricity Generation' id='State Name'; title 'ENERGY Model Example'; title2 'ENERGY_W Data'; title3; cards; 1491 520 17089 525 834 570833 4.2 AK 4014 790 10630 2396 10827 52078 33.8 AR 5616 898 13008 3483 11299 113508 61.6 AZ 39553 6970 16059 28323 132638 156299 126.0 CA 4594 902 14187 3300 12046 103595 30.9 CO 1581 266 14294 1096 1405 6425 7.6 HI 4820 942 12213 2830 14469 55965 27.7 IA 1572 355 11177 1003 3057 82412 6.7 ID 4826 1057 13425 2496 12909 81778 31.4 KS 11322 3450 10793 4407 16426 44521 56.8 LA 6756 1315 13785 4308 23322 79548 40.3 MN 8324 1511 13240 5140 25917 68945 59.7 MO 1457 334 11371 805 1112 145388 24.8 MT 1425 311 10844 667 979 69300 27.4 ND 2732 536 12567 1603 5819 76644 20.6 NE 2479 524 10672 1510 1653 121335 26.4 NM 1899 355 15121 1054 1279 109894 20.3 NV 5232 1280 10956 3234 9857 68655 44.0 OK 4255 880 12687 2768 11610 96184 41.0 OR 1115 203 11369 714 1476 75952 7.9 SD 36304 9583 12908 16834 63899 262017 221.2 TX 2548 534 10650 1691 4883 82073 29.6 UT 6929 1807 14347 4652 19016 66511 83.6 WA 1323 377 11803 480 493 96989 39.1 WY ; data energy; set energy_w; q=.; p=.; run; /* Forecasting Average Price and Quantity */ proc model model=en_mod noprint; solve p q / forecast data=energy out=en_outw(drop=_type_ _mode_ _errors_ rename=(p=p_fore q=q_fore)); run; /* Merging Data Sets */ data energy_p; merge energy_w en_outw; by id; label p_fore='Forecasted Average Price' q_fore='Forecasted Quantity'; run; /* Plotting Forecasts */ proc plot data=energy_p vpct=60; plot p*p_fore='*'; plot p*p_fore='*' $ id;