* * Martin, Hurn, Harris, "Econometric Modelling with Time Series" * Application 15.8.1, from pp 567-571 * Hodrick-Prescott filter * open data "usgdp.dat" calendar(q) 1940:1 data(format=prn,nolabels,org=columns) 1940:01 2000:01 usgdp * set logy = 100.0*log(usgdp) * * This is how you would HP-filter a data series using RATS * filter(type=hp) logy / hplogy graph(footer="Figure 15.4 Log of GDP with smoothed trend component",\$ key=upleft,klabels=||"Smoothed","Actual"||) 2 # hplogy 1940:1 1952:4 # logy 1940:1 1952:4 * * This does the analysis by Kalman filtering * @localdlm(type=trend,shocks=trend,a=a,c=c,f=f) @localdlminit(trend=sigsqzeta,irreg=sigsqc) logy * * Freely estimate both component variances * nonlin sigc sigzeta compute sigc=sqrt(sigsqc),sigzeta=sqrt(sigsqzeta) dlm(presample=diffuse,a=a,c=c,f=f,sv=sigc^2,sw=sigzeta^2,y=logy,type=smooth,\$ method=bfgs) / xstates * * Pegging the variance to 1 in the next two examples doesn't make sense * as a general procedure without also using VAR=CONCENTRATE, which is * what we do. So the results for the estimates don't match. However, the * smoothed estimate of the state depends only upon relative variances, * so the HP-filtered data is the same regardless. * nonlin sigc=1.0 sigzeta dlm(presample=diffuse,a=a,c=c,f=f,sv=sigc^2,sw=sigzeta^2,y=logy,type=smooth,\$ method=bfgs,var=concentrate) / xstates * nonlin sigc=1.0 sigzeta=1.0/40.0 dlm(presample=diffuse,a=a,c=c,f=f,sv=sigc^2,sw=sigzeta^2,y=logy,type=smooth,\$ method=bfgs,var=concentrate) / xstates * set hpbykf = xstates(t)(1) * print 1940:1 1952:4 hplogy hpbykf