* * Example from 9.2.1 starting page 230. * open data bangla.dat data(format=free,org=columns) 1 34 p a * set logp = log(p) set loga = log(a) * linreg loga # constant logp * * %RESIDS is the series of residuals from the most recent regression. * print / %resids graph(footer="Figure 9.3 Least squares residuals plotted against time",$ hlabel="Observation",vlabel="Residuals") # %resids * * To get standard errors corrected for both heteroscedasticity AND * autocorrelation, you use the LAGS option and an option to indicate the lag * window type. By far the most common of these is Newey-West, which is indicated * by LWINDOW=NEWEY. The standard errors shown in the next are done with LAGS=3, * and also include a degrees of freedom adjustment. If you multiple the standard * errors in RATS by sqrt(34.0/32.0), you'll get the same values. * linreg(lwindow=newey,lags=3) loga # constant logp * * AR1 is specialized instruction for estimating a linear regression with AR(1) * errors. In addition to the coefficients from the regression, it shows the * estimated value for the coefficient in the AR(1) error process. This is called * "RHO" in the output. * ar1 loga # constant logp * * This does the unrestricted dynamic model and then uses SUMMARIZE to examine the * restriction implied by the AR(1) errors. This is the first example that uses the * {lag} notation. logp{1} means the first lag of logp, that is, logp(t-1). Note * well that positive values mean lags. lags are much more commonly used than * leads, so RATS adopts the notation that fits with that. * linreg loga # constant logp logp{1} loga{1} summarize %beta(3)+%beta(4)*%beta(2) * linreg loga # constant logp * * REGCORRS is a regression post-processing procedure for examining the auto- * correlations of the residuals. The NUMBER option selects the number of * autocorrelations to compute; we've chosen 6 here to match that shown in the * text. The TABLE option asks for a table of values - by default, the information * is only shown graphically. * * You'll note that the results shown here are a bit different from those shown in * the text. There are several (justifiable) ways to compute autocorrelations. The * difference between those shown in the text and those done by REGCORRS lies in * the calculation of the denominator in formula 9.32. REGCORRS computes this using * the sum of squares over the whole sample. Thus the denominator in each * calculation for r1,...,r6 is the same even though there are fewer terms in the * numerator as you go to higher lags. The estimates in the text adjust for the * sample and are the results that you would get if you were compute r4 (for * instance) as the sample correlation between e(t) and e(t-4). * @regcorrs(number=6,report) * ar1 loga # constant logp @regcorrs(number=6,report) * * LM test for serial correlation. Note that because %RESIDS gets rewritten by each * regression, we need to copy the information into another series ("E") so we can * use it later. * linreg loga # constant logp set e = %resids * * First test type, looking at the t-statistic in the augmented regression. * linreg loga # constant logp e{1} * * Second test type, looking at the T x R^2 from a regression with the residuals as * dependent variable. The first form of this (which is probably more standard) * just omits the first observation. * linreg e # constant logp e{1} cdf(title="LM test for serial correlation. First observation omitted") chisqr %trsquared 1 * * The second form creates a new series which is zero where the lag isn't naturally * defined. This will give the results shown in the text. * set elag = %if(%valid(e{1}),e{1},0.0) linreg e # constant logp elag cdf(title="LM test for serial correlation. Lagged residuals zeroed") chisqr %trsquared 1