* * Example 17.8 from page 528, 17.9 from page 530 and 17.10 from page 533 * Augmented Dickey-Fuller tests and Bayesian unit root test * cal(q) 1947 open data gnptbill.txt data(format=prn,org=obs) 1947:1 1989:1 * * Direct calculations for 17.8 * set dtbill = tbill-tbill{1} linreg tbill # constant tbill{1} dtbill{1 to 4} * * The easiest way to compute the sum of a set of coefficients is with the * SUMMARIZE instruction, which produces %SUMLC as the sum. (The "LC" stands for * linear combination, as SUMMARIZE can also handle more general linear * combinations. A couple of other possibilities are the brute force * %beta(3)+%beta(4)+%beta(5)+%beta(6), or %sum(%xsubvec(%beta,3,6)) * summarize # dtbill{1 to 4} disp "ADF p-test=" %nobs/(1-%sumlc)*(%beta(2)-1) disp "ADF t-test=" (%beta(2)-1)/%stderrs(2) disp "Test of final lag" %tstats(6) "with p-value" %ttest(%tstats(6),%ndf) * * Using the DFUNIT procedure * @dfunit(lags=4,nottest) tbill @dfunit(lags=4,ttest) tbill * * Example 17.9 * set lgnp = 100.0*log(gnp) set trend = t set dgnp = lgnp-lgnp{1} * linreg lgnp # constant lgnp{1} trend dgnp{1 to 4} summarize # dgnp{1 to 4} disp "ADF p-test=" %nobs/(1-%sumlc)*(%beta(2)-1) disp "ADF t-test=" (%beta(2)-1)/%stderrs(2) * * This computes the joint F-test. We suppress the printing, because it will give * a misleading p-value, based upon an F and not the non-standard distribution * test(noprint) # 2 3 # 1.0 0.0 disp "ADF Joint test for p=1, and trend=0" %cdstat * * Using DFUNIT * @dfunit(lags=4,det=trend,nottest) lgnp @dfunit(lags=4,det=trend,ttest) lgnp * * Choosing a lag length as described on page 530 * compute maxlag=10 linreg lgnp # constant lgnp{1} trend dgnp{1 to maxlag} do lag=maxlag,1,-1 exclude(noprint) # dgnp{lag to maxlag} disp lag @5 *.### %cdstat %signif if %signif<.05 break end do lag * * The loop breaks with the largest value of lag such that such that the lags of * dgnp from <> to the end is significant. Since that means that <>+1 to * the end is insignificant, we can use that value of lag on the dfunit procedure. * If none of the tests comes out significant, lag will end up being equal to 0, * as that will be the value of lag which forces an exit of the loop, which again * is what we want. * @dfunit(lags=lag,trend) lgnp * * Example 17.10 * There is a procedure for a Bayesian unit root test (BAYESTST), which uses a * more informative prior, but that doesn't apply to a regression with a trend. * The results for the non-informative prior require only looking at a standard * t-test but adjusting it to a one-sided alternative. That requires dividing the * usual ttest significance level by 2. * linreg lgnp # constant lgnp{1} trend dgnp{1 to 4} compute tvalue=(1-%beta(2))/%stderrs(2) * disp "One-sided t-test for p=1" disp "Test Statistic" tvalue "P-value" %ttest(tvalue,%ndf)/2