* * HPFILTER.RPF * Example of local trend state-space model * * RATS User's Guide, Example from Section 10.7 * cal(q) 1959:1 open data haversample.rat data(format=rats) 1959:1 2006:4 gdph log gdph / lgdp * * This uses the built-in HP filter in the FILTER instruction * filter(type=hp,tuning=1600.0) lgdp / hpfilt * * The HP filter is a local trend model. The system matrices for this can * be generated using the procedure LOCALDLM with TYPE=TREND and * SHOCKS=TREND. * @localdlm(type=trend,shocks=trend,a=ahp,c=chp,f=fhp) * * This is the relative variance of the measurement error to trend rate * disturbance. * compute lambda = 1600.0 * dlm(a=ahp,c=chp,f=fhp,sv=1.0,sw=1.0/lambda,presample=diffuse,\$ type=smooth,var=concentrate,y=lgdp) / hpstates * * Extract the local trend rate, which is the second state. * set hprate = hpstates(t)(2) * * Estimate the (log of the) variances. This is *not* a good idea. The * "smoothed" trend is almost exactly equal to the series. * nonlin lsv lsw compute lsv=-3.0,lsw=-7.0 dlm(a=ahp,c=chp,f=fhp,y=lgdp,sv=exp(lsv),sw=exp(lsw),\$ presample=diffuse,type=smooth,method=bfgs) / ltstates * * Extract the trend rate from this and graph vs the HP estimate. * set ltrate = ltstates(t)(2) graph(header="Comparison of Local Trend Rates",key=below,\$ klabels=||"From HP Filter","From Estimated Local Trend"||) 2 # hprate # ltrate