* * CHAPTER 14 * Page 528 * * The CALENDAR instruction here indicates that the data are quarterly beginning in * 1957 (quarter 1). The ALL (short for ALLOCATE) is used here to set the data set * end at 2005 quarter 1. * cal(q) 1957 all 2005:1 * * Four of the series are actually collected on a monthly basis. RATS provides * several ways to convert these to quarterly. The first two (LHUR=unemployment * rate and PUNEW=price index) are compacted by taking averages of the three * monthly values. The second two (FYFF=Federal funds rate and EXRUK=exchange rate * vs UK pound) take the final month from the quarter. GDP_JP is a quarterly * series, so no special options are required. * open data ch14-16_macro2e.rat data(for=rats,compact=average) / lhur punew data(for=rats,compact=last) / fyff exruk data(for=rats) / gdp_jp * set jap_gdp = log(gdp_jp) ;* GDP for Japan set d_jap_gdp = 400*log(gdp_jp/gdp_jp{1}) set infl = 400*log(punew/punew{1}) ;* US Inflation set infl1 = 400*(punew/punew{1}-1.0) ;* Alternative US Inflation set dinfl = infl-infl{1} ;* Change in Inflation set dinfl1 = infl1-infl1{1} set ddinfl = dinfl-dinfl{1} ;* Change in Change in Inflation set dlhur = lhur-lhur{1} ;* Change in Unemployment Rate * * Figure 14.1 * This uses the SPGRAPH instruction which (among other things) can put multiple * graphs on a single page. The VFIELDS=2 indicates two fields in the vertical * direction, one atop the other. The SPGRAPH(DONE) after the two graph * instructions signals that the overall graph is finished. * * The recession indicator series isn't provided on the data set It's generated * here, using the NBER series. The shading option on the GRAPH for the * unemployment rate is employed to shade the sets of entries where the RECESSION * series is 1. * set recession = 0.0 set recession 1960:2 1961:1 = 1.0 set recession 1969:4 1970:4 = 1.0 set recession 1973:4 1975:1 = 1.0 set recession 1980:1 1980:3 = 1.0 set recession 1981:3 1982:4 = 1.0 set recession 1990:3 1991:1 = 1.0 set recession 2001:2 2001:4 = 1.0 * spgraph(vfields=2,header="Figure 14.1 Inflation and Unemployment in the United States, 1960-2004") graph(hlabel="(a) US CPI Inflation Rate") # infl 1960:1 2004:4 graph(hlabel="(b) US Unemployment Rate",shading=recession) # lhur 1960:1 2004:4 spgraph(done) print(dates) 1960:1 2004:4 infl lhur * * * Table 14.1 * set infllag = infl1{1} set dinfl1 = infl1-infllag print(dates) 2004:1 2005:1 punew infl1 infllag dinfl1 * * Table 14.2 * * cor(number=4,method=yule) infl 1960:1 2004:4 cor(number=4,method=yule) dinfl 1960:1 2004:4 *** smpl 1990:1 2004:4 stats d_jap_gdp * * This does most of Figure 14.2. The NYSE daily data aren't on this data set. * This again uses SPGRAPH...SPGRAPH(DONE) to wrap around the three graphs * VFIELDS=2 and HFIELDS=2 sets up a 2x2 matrix of graphs. * smpl 1960:1 2004:4 spgraph(header="Figure 14.2 Three Economic Time Series",vfields=2,hfields=2) graph(hlabel="(a) Federal Funds Interest Rate") # fyff graph(hlabel="(b) Logarithm of Nominal GDP in Japan") # jap_gdp graph(hlabel="(c) U.S. Dollar/British Pound Exchange Rate") # exruk spgraph(done) print(dates) 1960:1 2004:4 fyff jap_gdp exruk * * Equation (14.7) * linreg(robust) dinfl 1962:1 2004:4 # constant dinfl{1} * * Forecasts computed from Equation (14.7) * * Forecast of the change in inflation for 2005:1. * (There are simpler commands to do this, which we'll show below, but this * follows the calculation done in the text). * compute fd2005=%beta(1)+%beta(2)*dinfl(2004:4) * * Forecast of inflation itself * compute f2005=infl(2004:4)+fd2005 disp "Forecast of Change" @30 fd2005 disp "Forecast of Inflation Rate" @30 f2005 disp "Actual Inflation Rate" @30 infl(2005:1) * * Equation (14.13) * To run a regression with many lags, you can use the notation shown below: * variable{list of lags}. "TO" can be used to abbreviate a set of consecutive * lags. * linreg(robust) dinfl 1962:1 2004:4 # constant dinfl{1 to 4} * * Joint test of the lags above 1 * exclude # dinfl{2 to 4} * * Forecast * compute fd2005=%beta(1)+%beta(2)*dinfl(2004:4)+%beta(3)*dinfl(2004:3)+%beta(4)*dinfl(2004:2)+%beta(5)*dinfl(2004:1) compute f2005=infl(2004:4)+fd2005 disp "Forecast of Change" @30 fd2005 disp "Forecast of Inflation Rate" @30 f2005 disp "Actual Inflation Rate" @30 infl(2005:1) ** ** Figure 14.3 is done below. (It uses annual, not quarterly, data) ** ** Equation (14.16) ** linreg(print,robust) dinfl 1962:1 2004:4 # constant dinfl{1 to 4} lhur{1} * * The instruction PRJ can also be used to compute this type of forecast. It's the * same calculation as shown above, that is, sum of coefficients x observed data. * This will still only forecast the rate of change, since that's the dependent * variable in the regression. This produces the series fd2005s, though in this * case we only want the value for the single entry 2005:1. * prj fd2005s 2005:1 2005:1 compute f2005=infl(2004:4)+fd2005s(2005:1) disp "Forecast of Change" @30 fd2005s(2005:1) disp "Forecast of Inflation Rate" @30 f2005 disp "Actual Inflation Rate" @30 infl(2005:1) disp "Value of lhur in 2004:IV" @30 lhur(2004:4) ** ** Equation (14.17) ** linreg(print,robust) dinfl 1962:1 2004:4 # constant dinfl{1 to 4} lhur{1 to 4} exclude # lhur{2 to 4} exclude # lhur{1 to 4} * * Forecasts (again done using PRJ). The forecast is different than shown in 14.18 * because of rounding differences (PRJ does the calculations at full precision, * while those in the text have coefficients and data rounded to one or two * decimal places). * prj fd2005s 2005:1 2005:1 compute f2005=infl(2004:4)+fd2005s(2005:1) disp "Forecast of Change" @30 fd2005s(2005:1) disp "Forecast of Inflation Rate" @30 f2005 disp "Actual Inflation Rate" @30 infl(2005:1) print(dates) 2004:1 2004:4 lhur * * Table 14.4 * BIC Calculation * report(action=define,hlabels=||"p","SSR(p)/T","ln(SSR(p)/T)","(p+1)ln(T)/T","BIC(p)","R**2"||) do maxlag=0,6 if maxlag==0 { linreg(noprint,robust) dinfl 1962:1 2004:4 # constant } else { linreg(noprint,robust) dinfl 1962:1 2004:4 # constant dinfl{1 to maxlag} } compute c2=%rss/%nobs,c3=log(c2),c4=%nreg*log(%nobs)/%nobs compute bic=c3+c4 report(row=new,atcol=1) maxlag c2 c3 c4 bic %rsquared end do report(action=format,picture="*.###") report(action=show) ** ** Equation (14.28) ** linreg(robust) infl 1965:1 1981:4 # constant jap_gdp ** ** Equation (14.29) ** linreg(robust) infl 1982:1 2004:4 # constant jap_gdp * * Equation (14.34) * Dickey-Fuller test * linreg dinfl 1962:1 2004:4 # constant infl{1} dinfl{1 to 4} * * QLR Results -- Has the PC been Stable? * compute [integer] n = (2004:4) - (1962:1) compute [integer] tskip = fix(0.15*n) compute t1 = (1962:1)+tskip+1 compute t2 = (2004:4)-tskip-1 set fstat t1 t2 = 0.0 * do t3 = t1,t2 set dc = t > t3; set d1 = dc*lhur{1} set d2 = dc*lhur{2} set d3 = dc*lhur{3} set d4 = dc*lhur{4} linreg(noprint,robust) dinfl 1962:1 2004:4 # constant dinfl{1 to 4} lhur{1 to 4} dc d1 d2 d3 d4 compute fac = float(%ndf)/float(%nobs) exclude(noprint) # dc d1 d2 d3 d4 set fstat t3 t3 = fac*%cdstat/5.0 end do * extremum(print) fstat compute qlr = %maximum disp "qlr" @30 qlr spgraph graph(vgrid=||4.53,3.66||,header="Figure 14.5 F-Statistics Testing for a Break in the Phillips Curve") # fstat t1 t2 grtext(entry=1990:1,y=4.53,valign=center) "1% Critical Value" grtext(entry=1990:1,y=3.66,valign=center) "5% Critical Value" spgraph(done) print(dates) / fstat * * Out-of-sample forecasting .. figure 14.5 * do t1=1998:4, 2004:3 linreg(noprint) dinfl 1982:1 t1 res coef # constant dinfl{1 to 4} lhur{1 to 4} prj dfcst t1+1 t1+1 set fcst t1+1 t1+1 = dfcst+infl{1} end do t1 set fcst_err 1999:1 2004:4 = infl-fcst statistics fcst_err 1999:1 2004:4 print(dates) 1999:1 2004:4 infl fcst fcst_err graph(style=lines,header="Figure 14.6 U.S. Inflation and Pseudo Out-of-Sample Forecasts") 2 # infl 1999:1 2004:4 # fcst 1999:1 2004:4 print(dates) 1999:1 2004:4 infl fcst * * Full Sample Estimate * linreg(robust) dinfl 1982:1 2004:4 res coef # constant dinfl{1 to 4} lhur{1 to 4} * linreg(robust) dinfl 1982:1 1998:4 res coef # constant dinfl{1 to 4} lhur{1 to 4} * ** ** Replication for figure 14.3 ** The end(reset) instruction re-initializes memory. The same data ** are read in, but as annual data instead. ** end(reset) ** cal 1960 data(for=rats,compact=average) / lhur punew set infl = 100.0*log(punew/punew{1}) set dinfl = infl{-1}-infl linreg dinfl # constant lhur scatter(style=dots,lines=%beta,header="Figure 14.3 Scatterplot of Change in Inflation(t->t+1) vs Unemployment") # lhur dinfl linreg dinfl # constant lhur prj dinfl_fit * * Can You Beat the Market? (pg 540 & 573) * cal(m) 1931:1 all 2002:12 open data ch14_stockreturns.asc data(for=free,org=obs) / year month exreturn ln_divyield close data set d_ln_divyield = ln_divyield(t)-ln_divyield(t-1) * * AR Models -- Part 1 Box * smpl 1960:1 2002:12 linreg(robust) exreturn # constant exreturn{1} exclude # exreturn{1} linreg(robust) exreturn # constant exreturn{1 to 2} exclude # exreturn{1 to 2} linreg(robust) exreturn # constant exreturn{1 to 4} exclude # exreturn{1 to 4} * * * ADL Models -- Part 2 Box * linreg(robust) exreturn 1960:1 2002:12 # constant exreturn{1} d_ln_divyield{1} exclude # exreturn{1} d_ln_divyield{1} linreg(robust) exreturn 1960:1 2002:12 # constant exreturn{1 to 2} d_ln_divyield{1 to 2} exclude # exreturn{1 to 2} d_ln_divyield{1 to 2} linreg(robust) exreturn 1960:1 1992:12 # constant exreturn{1} ln_divyield{1} * * Pseudo-Out-of-Sample * set fcst_adl = 0 set fcst_const = 0 do t1=1992:12, 2002:11 linreg(noprint) exreturn 1960:1 t1 # constant exreturn{1} ln_divyield{1} prj fcst_adl t1+1 t1+1 linreg(noprint) exreturn 1960:1 t1 # constant prj fcst_const t1+1 t1+1 end do t1 * * The SSTATS instruction can be used for "queries" on expressions constructed from * RATS expressions. It can compute the sum (by default), mean, product, minimum or * maximum for one or more expressions. Here, it being used to compute the * (uncentered) second moments of forecast errors. Note, by the way, that the * UFOREERRORS procedure computes a wide range of statistics like this on forecast * performance. * declare vector rmse(3) sstats(mean) 1993:1 2002:12 exreturn**2>>rmse(1) (exreturn-fcst_const)**2>>rmse(2) (exreturn-fcst_adl)**2>>rmse(3) disp "RMSFE of Zero Return" @25 *.## sqrt(rmse(1)) disp "RMSFE of Constant" @25 *.## sqrt(rmse(2)) disp "RMSFE of ADL" @25 *.## sqrt(rmse(3))