* * Example 7.6 from pp 136-137 * open data tablef2-2[1].txt calendar 1960 data(format=prn,org=columns) 1960:1 1995:1 year g pg y pnc puc ppt pd pn ps pop * set loggpop = log(g/pop) set logypop = log(y) set logpg = log(pg) set logpnc = log(pnc) set logpuc = log(puc) set trend = year set predummy = t<=1973:1 set postdummy = t>=1974:1 * * The first regression in Table 7.6 is loggpop run over the full sample, the * third is over 1960:1 to 1973:1 and the fourth 1974:1 to 1995:1. The second is * done using two intercepts: one for the pre-shock period, and one for * post-shock. We're going to need to save the sum of squared residuals from each * for future tests. * linreg loggpop # constant logypop logpg logpnc logpuc trend compute rssr=%rss linreg loggpop # predummy postdummy logypop logpg logpnc logpuc trend compute rsssplit=%rss linreg loggpop 1960:1 1973:1 # constant logypop logpg logpnc logpuc trend compute rsspre=%rss linreg loggpop 1974:01 1995:01 # constant logypop logpg logpnc logpuc trend compute rsspost=%rss * * Test for overall constancy of the regression. * compute chow=((rssr-(rsspre+rsspost))/6)/((rsspre+rsspost)/(36-12)) cdf(title="Chow Test for Split at 1973") ftest chow 6 24 * * For the predictive test, we need to create a dummy variable which leaves out * the years 1974, 1975, 1980 and 1981. * set smpl = year<=1973.or.(year>=1976.and.year<=1979).or.year>=1982 linreg(smpl=smpl) loggpop # constant logypop logpg logpnc logpuc trend * * The Chow predictive test uses the small sample regression (the one just run) as * the base, so the denominator is just the sum of squared residuals/degrees of * freedom. * compute chowp=((rssr-%rss)/4)/(%rss/%ndf) cdf(title="Chow Predictive Test Leaving Out Oil Shocks") ftest chowp 4 %ndf * * Identical test using dummies for the four periods we want to leave out * set d1974 = year==1974 set d1975 = year==1975 set d1980 = year==1980 set d1981 = year==1981 linreg loggpop # constant logypop logpg logpnc logpuc trend d1974 d1975 d1980 d1981 exclude(title="Testing Dummies for 1974, 1975, 1980, 1981") # d1974 d1975 d1980 d1981 * * Testing constancy apart from differing intercepts. This uses the sum of squared * residuals from the 2nd of the four early regressions, with degrees of freedom * in the numerator reduced to 5. * compute chowx1=((rsssplit-(rsspre+rsspost))/5)/((rsspre+rsspost)/(36-12)) cdf(title="Chow Test for Split at 1973, Allowing Different Intercepts") ftest chowx1 5 24 * * Allowing intercept, income and own price coefficients to differ. We need * dummies for the subsamples times those variables as well. We can get the * equivalent result by using all six original variables, and including dummy * multiples for those three variables over just one of the two subsamples. * set postypop = postdummy*logypop set postpg = postdummy*logpg * linreg loggpop # constant logypop logpg logpnc logpuc trend postdummy postypop postpg * * This is now computed just like the original Chow test, it's just that the * numerator degrees of freedom will now be 3. * compute chow=((%rss-(rsspre+rsspost))/3)/((rsspre+rsspost)/(36-12)) cdf(title="Chow Test for Split at 1973, Allowing Different Intercept, Income and Own Price") ftest chow 3 24 * * Rerun the subsample regressions. Get the covariance matrices and coefficient * vectors to compute the Wald test. For an OLS regression the covariance matrix * is %seesq*%xx. (%xx is the inv(X'X) array). Since we don't need to see the * results again, we use the NOPRINT option. * linreg(noprint) loggpop 1960:1 1973:1 # constant logypop logpg logpnc logpuc trend compute vpre=%seesq*%xx,betapre=%beta linreg(noprint) loggpop 1974:01 1995:01 # constant logypop logpg logpnc logpuc trend compute vpost=%seesq*%xx,betapost=%beta compute vdiff=vpre+vpost,betadiff=betapost-betapre compute wald=%qform(inv(vdiff),betadiff) cdf(title="Wald Test for Split at 1973") chisqr wald 6 * * Hansen test. We need the residuals from the original full sample regression. * This works this out in detail. You can also use the procedure STABTEST. * linreg(noprint) loggpop / resids # constant logypop logpg logpnc logpuc trend dec vect s(%nreg+1) f(%nreg+1) fx(%nreg) dec symm ss(%nreg+1,%nreg+1) ff(%nreg+1,%nreg+1) compute s=%const(0.0),ss=%const(0.0),ff=%const(0.0) do time=%regstart(),%regend() compute fx=resids(time)*%eqnxvector(0,time) ewise f(i)=%if(i<=%nreg,fx(i),resids(time)**2-%rss/%nobs) compute ff=ff+%outerxx(f) compute s=s+f compute ss=ss+%outerxx(s) end do time compute h=(1.0/%nobs)*%dot(inv(ff),ss) disp "Hansen Test for Structural Stability" h * * CUSUM test. This uses the procedure RegRecursive, which computes recursive * residuals from the last regression. The cusum option generates the CUSUM graph. * ???? @RegRecursive(cusum) * * * Bonus coverage. This generates something similar to Table 7.6 using the REPORT * instruction. * report(action=define,hlabels=||"Coefficients","1960-1995","Pooled","Preshock","Postshock"||) report(atcol=1,atrow=1,fillby=col) "R**2" "Standard Error" "Sum of Squares" * linreg loggpop # constant logypop logpg logpnc logpuc trend compute rssr=%rss report(regressors) report(column=current,atrow=1,fillby=col) %rsquared sqrt(%seesq) %rss linreg loggpop # predummy postdummy logypop logpg logpnc logpuc trend report(regressors) report(column=current,atrow=1,fillby=col) %rsquared sqrt(%seesq) %rss linreg loggpop 1960:1 1973:1 # constant logypop logpg logpnc logpuc trend compute rsspre=%rss report(regressors) report(column=current,atrow=1,fillby=col) %rsquared sqrt(%seesq) %rss linreg loggpop 1974:01 1995:01 # constant logypop logpg logpnc logpuc trend compute rsspost=%rss report(regressors) report(column=current,atrow=1,fillby=col) %rsquared sqrt(%seesq) %rss report(action=show,window="Table 7.6")