* * Examples from section 12.6, pages 462-474 * open data table12-4.prn cal 1959 data(format=prn,org=columns) 1959:1 1998:1 linreg y / resids # constant x set sres = resids/sqrt(%seesq) graph(overlay=line) 2 # resids # sres * set logy = log(y) set logx = log(x) linreg logy / lresids # constant logx * * Runs test. Counting pluses and minuses is pretty easy - just create dummies for * positive and negative values, and use SSTATS to sum the number. Counting runs * requires a bit of ingenuity; one run starts at the beginning, then the start of * each other run is marked with a sign switch, so plus will be different from * plus lagged once. The SET instruction for creating the switch dummy uses the * FIRST option, which allows the first entry to be set differently from the * others, without requiring separate SET instructions for the two ranges. * * We compare this with the RunTest procedure, which computes a slightly different * test statistic. * set plus = (resids>=0.0) set minus = (resids<0.0) set(first=1.0) switch = plus<>plus{1} * sstats / plus>>nplus minus>>nminus switch>>nruns compute rmean=2*nplus*nminus/%nobs+1 compute rvar =2*nplus*nminus*(2*nplus*nminus-%nobs)/(%nobs**2*(%nobs-1)) * * Note that the mean value in the text is miscalculated. It appears to have been * computed without the 2*. * disp "Plus" nplus "Minus" nminus "Runs" nruns disp "Mean" rmean "Variance" rvar * compute zrun=(nruns-rmean)/sqrt(rvar) cdf(title="Runs Test") normal zrun * @RunTest plus * * Asymptotic Durbin-Watson significance (p 472) * linreg y / resids # constant x compute zdurbin=sqrt(%nobs)*(1-%durbin/2) cdf normal zdurbin * * BG test * linreg resids # constant x resids{1 to 6} compute bgtest=(40-6)*%rsquared cdf(title="Breusch-Godfrey Test") chisqr bgtest 6 * * Check for significance of lags 2 through 6 * exclude # resids{2 to 6} * * Rerun BG with just one lag * linreg resids # constant x resids{1} compute bgtest=(40-1)*%rsquared cdf(title="Breusch-Godfrey Test") chisqr bgtest 1