* * ExampleFour.RPF * RATS Introduction, Example from Section 1.5 * open data ex152.xls calendar(m) 1986:1 data(format=xls,org=columns) 1986:1 1995:10 hs6fr * * Computing filtered series using a 7-period moving average * and the Hodrick-Prescott filter: * filter(type=centered,width=7) hs6fr / flat7 filter(type=hp) hs6fr / hpfilter * * Generate a graph comparing the original series and the * two filtered series: * GRAPH(STYLE=LINE,FOOTER="Moving Average versus HP Filtering",KEY=UPRIGHT) 3 # HS6FR # FLAT7 # HPFILTER * * Same thing, but over a limited range of observations: * GRAPH(STYLE=LINE,FOOTER="Moving Average versus HP Filtering",KEY=UPRIGHT) 3 # HS6FR 1990:1 1995:12 # FLAT7 1990:1 1995:12 # HPFILTER 1990:1 1995:12 * * This filters out the trend component: * filter(remove=trend) hs6fr / detrend * * This save the removed trend into a new series by taking the difference * of the original and detrended data: * set removed = hs6fr-detrend * * The ESMOOTH instruction is applied to the detrended series: * ESMOOTH(ALPHA=0.2,SMOOTHED=ESMOOTH) DETREND * * Then we replace ESMOOTH with the sum of its previous values and the * trend component removed earlier: * set esmooth = esmooth+removed * * Graph the original, HP filter, and exponentially smoothed series: * GRAPH(STYLE=LINE,HEADER="Exponential Smoothing vs HP Filter",KEY=ABOVE,NOKBOX) 3 # HS6FR # HPFILTER # ESMOOTH * * This ESMOOTH command is applied to the original series (not the * detrended version). It includes trend and seasonal components to * produce a smoothed series as well as forecasts for 8 periods from the * end of the original data: * ESMOOTH(TREND=LINEAR,SEASONAL=MULTIPLICATIVE,ESTIMATE,SMOOTHED=ESMOOTH,$ FORECAST=ESMOOTH_FORE,STEPS=8) HS6FR * * This graphs the original series followed by the forecasts: * GRAPH(STYLE=LINE,HEADER="Exponential Smoothing Forecast",KEY=ABOVE,NOKBOX) 3 # HS6FR # ESMOOTH # ESMOOTH_FORE * * Seasonally adjusting data using ESMOOTH * esmooth(seasonal=multiplicative,estimate,$ smoothed=smoothed,fitted=fitted) hs6fr graph(header="Seasonally Adjusted Data",key=above,nokbox) 3 # hs6fr # smoothed # fitted * * OLS regression and forecast on seasonally adjusted data. * First, define a time trend series: * SET TREND * 1996:12 = T * * Then regress on constant and trend: * linreg(define=forecast_eq) smoothed 1992:1 * # constant trend uforecast(from=1995:11,to=1996:12,equation=forecast_eq) hsfore graph 3 # hs6fr 1992:1 * # smoothed 1992:1 * # hsfore * * Demonstrating the PRINT instruction * print print 1990:1 1996:6 hs6fr esmooth esmooth_fore print / hs6fr esmooth esmooth_fore print(window="ESMOOTH Forecasts") / hs6fr esmooth_fore print(picture="*.#") / hs6fr