HPFILTER.RPF examines the state-space model underlying the Hodrick-Prescott filter using the DLM instruction, relaxing the variance ratio used in the HP filter.
The Hodrick-Prescott (1997) filter has been used extensively to extract a growth component from macroeconomic series, leaving the cyclical element. It computes the estimated growth component \(g\) of a series \(x\) to minimizes the sum over \(t\) of:
\({\left( {{x_t} - {g_t}} \right)^2} + \lambda {\left( {{g_t} - 2{g_{t - 1}} + {g_{t - 2}}} \right)^2}\)
The first term is the squared gap between the growth component and the data (so it's expected that the growth component will be close to the actual data), while the second measures the "second derivative" of the growth component. The value of \(\lambda\) is set in advance based upon the frequency of the data (1600 for quarterly data)—a high value produces a "stiffer" growth component.
This is a special case of a well-studied small state-space model called a local trend model, where the state equation can be written
\(\left[ {\begin{array}{*{20}{c}} {{g_t}} \\ {{\tau _t}} \\ \end{array}} \right] = {\rm{ }}\left[ {\begin{array}{*{20}{c}} 1 & 1 \\ 0 & 1 \\ \end{array}} \right]{\rm{ }}\left[ {\begin{array}{*{20}{c}} {{g_{t - 1}}} \\ {{\tau _{t - 1}}} \\ \end{array}} \right] + \left[ {\begin{array}{*{20}{c}} 0 \\ 1 \\ \end{array}} \right]{w_t}\)
where \({{\tau _t}}\) is the local rate of trend growth, and the measurement equation is
\({y_t} = {g_t} + {v_t}\)
The HP filter fixes the ratio of the variances between the measurement error (\({v_t}\)) and the shock to the trend rate of growth (\({w_t}\)) in a way which seems to produce the right level of stiffness in the trend for typical economic data. \({{g_t}}\) can be computed by Kalman smoothing the state-space model and can be done simply in RATS by using the FILTER instruction with the option TYPE=HP:
filter(type=hp,tuning=1600.0) lgdp / hpfilt
(The 1600 is actually the default value for TUNING for quarterly data, so it's not strictly necessary).
The program then further analyzes the underlying local trend model, using DLM. The local trend system matrices are generated using the @LOCALDLM procedure:
@localdlm(type=trend,shocks=trend,a=ahp,c=chp,f=fhp)
and then the model is smoothed using the set ratio of variances (SV is 1.0, SW is 1.0/LAMBDA)
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
The first smoothed state will be exactly the same as the output from the FILTER instruction. The time path of the second smoothed state is the estimate of the rate of growth:
set hprate = hpstates(t)(2)
It then estimates (rather than fixing) the two variances (in log form). This is not a good idea in situations like this—the fixed ratio is what actually gives content to the "trend", and freely estimating the variances generally gives a "trend" which much too closely tracks the data.
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
In the output from the DLM with estimated parameter variances, the variance of the measurement error being effectively zero (exp(-32) is roughly 1.e-14), which means that the trend is set to track the data almost perfectly. The following extracts the smoothed trend from this model and compares it graphically to the trend from the Hodrick-Prescott filter (black line). As is clear from the output, the trend rate is doing far too much adjusting to the data to be useful.
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
Full Program
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
Output
DLM - Estimation by BFGS
Convergence in 9 Iterations. Final criterion was 0.0000013 <= 0.0000100
Quarterly Data From 1959:01 To 2006:04
Usable Observations 192
Rank of Observables 190
Log Likelihood 598.2184
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. LSV -32.26173203 0.76483879 -42.18109 0.00000000
2. LSW -9.13491766 0.10256836 -89.06175 0.00000000
Graph