* * Examples from section 13.4, pages 519-524 * Specification tests * all 10 open data table7-4.prn data(format=prn,org=columns) * * Estimate linear, quadratic and cubic specifications and save the residuals from * each. * set xsq = x**2 set xcu = x**3 linreg y / resl # constant x linreg y / resq # constant x xsq linreg y / resc # constant x xsq xcu * * This graphs the three residual series on a single graph - the residuals will * show up as three colors or three dash patterns. * graph 3 # resl # resq # resc * * If you really want to show the residuals on three separate graphs, you need to * be careful. Three separate GRAPH instructions will give you a misleading view * because each will have a separate scale designed to fill the vertical distance. * You need to force a common scale by finding the maximum and minimum values * across the series being graphed, and using the MAX and MIN options on the * graphs. * * The SPGRAPH instruction is a "wrapper" for graphs which puts several graphs in * a single window or page. The HFIELDS option is used when you want graphs * arranged horizontally, and VFIELDS if you want them stacked vertically. Nothing * gets drawn until the SPGRAPH(DONE) instruction is executed. * table(noprint) / resl resq resc compute gmax=%maximum,gmin=%minimum * spgraph(hfields=3,xlabels=||"Linear","Quadratic","Cubic"||) graph(max=gmax,min=gmin) # resl graph(max=gmax,min=gmin) # resq graph(max=gmax,min=gmin) # resc spgraph(done) * * This data set was already ordered on the x variable. If your data are not * already ordered, and you want you want to use the DW to help detect * misspecification, you can use the ORDER instruction. While you can reorder the * entire dataset with ORDER(ALL) key series, we recommend just sorting copies of * the needed series. * set ox = x set oy = y order ox / oy * linreg oy # constant ox * * RESET test. Run the regression, get the fitted values and take quadratic and * possibly higher powers of them. Add those to the regression and test the * significance of the powers of the fitted variables. * linreg y # constant x prj yhat set yhatsq = yhat**2 set yhatcu = yhat**3 linreg y # constant x yhatsq yhatcu * * You can use the EXCLUDE instruction, or get a F-stat from the summary * statistics of the two regressions * exclude(title="RESET test with quadratic and cubic terms") # yhatsq yhatcu * * LM test. Regress residuals on the original variables + the candidates for * inclusion. The variable %trsq (which is T x the raw R**2) is the test * statistic. (The raw and centered R**2's are the same for the residuals from a * least squares regression which includes a constant. If you can also use * %TRSQUARED if you want to make sure that you get the centered R**2). * linreg y # constant x linreg %resids # constant x xsq xcu cdf(title="LM Test for Inclusion") chisqr %trsq 2 * * The above examples show how you the mechanics of the RESET tests. If you just * want to apply the test without going through those steps, you can use the * @RegRESET(h=power) procedure. Do this immediately after the regression. For the * cubic, you would use the option h=3. * linreg y # constant x @regreset(h=3)