Appendix E

COMPLETE PROGRAMS AND PROC IML ROUTINES

E.1 PROGRAM 1

This program was used in Chapter 2. It is used to analyze Table F3.1 of Greene (2003). In the following data step, we read in the raw data, create a trend variable, T, divide GNP and Invest by CPI, and then scale the transformed GNP and Invest time series so that they are measured in trillions of dollars.

`proc import out=invst_equation`
`datafile="C:\Temp\Invest_Data"`
`dbms=Excel Replace;`
`getnames=yes;`
`run;`
`data invst_equation;`
`set invst_equation;`
`T=_n_;`
`Real_GNP=GNP/(CPI*10);`
`Real_Invest=Invest/(CPI*10);`
`run;`
`/* The start of Proc IML routines.`
`*/proc iml;`
`/* Invoke Proc IML and create the X and Y matrices using the variables T, Real_GNP, and Real_Invest from the SAS data set invst_equation. */`
`use invst_equation;`
`read all var {’T’ ’Real_GNP’} into X;`
`read all var {’Real_Invest’} into Y;`
`/* Define the number of observations and the number of independent variables. */`
`n=nrow(X);`
`k=ncol(X);`
`/* Create a column of ones to the X matrix to account for the intercept term. */`
`X=J(n,1,1) ||X;`
`/* Calculate the inverse of X’X and use this to compute B_Hat */`
`C=inv(X’ *X);`
`B_Hat=C *X’ *Y;`
`/* Compute SSE, the residual sum of squares, and MSE, the residual mean square. */`
`SSE=y’ *y-B_Hat’ *X’ *Y;`
`DFE=n-k-1;`
`MSE=sse/DFE;`
`/* Compute SSR, the sums of squares due to the model; MSR, the sums of squares due to random error; and the F ratio. */`
`Mean_Y=Sum(Y)/n;`
`SSR=B_Hat’ *X’ *Y-n *Mean_Y * *2;`
`MSR=SSR/k;`
`F=MSR/MSE;`
`/* Compute R-Square ...`

Get Applied Econometrics Using the SAS® System now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.