Page 1 of 1

Where does the HP-filter estimates come from?

Posted: Wed Aug 24, 2011 7:39 am
by j.galimberti
Dear all,

I was trying to replicate the results obtained from the Eviews built-in Hodrick-Prescott filter, but I am a bit puzzled with some very small discrepancies.
I tried the matrix solution as in http://forums.eviews.com/viewtopic.php? ... k+prescott, but the results are not exaclty the same as those obtained directly from the hpf function (or by the series Proc menu), with some very small differences I agree, but still not the same. This led me to conclude that Eviews does not use this solution, which is more computationally expensive for long series due to the matrix inversion.

Then I tried with a state space formulation of an unobserved components model, with the following specification:

Code: Select all

@signal y = x + [var = c(1)] @state x = x(-1) + x_change(-1) @state x_change = x_change(-1) + [var = c(1)/lambda]
where lambda is a scalar object set to 1600.

Still, there are discrepancies with those obtained from the hpf function. I can see that my specification of the sspace may be innapropriate due to the lack of specification of initial state values. Thus, my guess is that Eviews function hpf computes the HP-filter using a sspace approach, but I wonder what would then be the correct specification to mimic this function?

Regards,
Jaqueson

Re: Where does the HP-filter estimates come from?

Posted: Thu Aug 25, 2011 12:31 am
by trubador

Code: Select all

@signal y = x + [var = exp(c(1))] @state x = 2*x(-1) - x_lag(-1) + [var = exp(c(1))/lambda] @state x_lag = x(-1)

Re: Where does the HP-filter estimates come from?

Posted: Sun Aug 28, 2011 12:16 pm
by j.galimberti
Thanks trubador, but still not matching exactly.

Re: Where does the HP-filter estimates come from?

Posted: Fri Mar 03, 2017 10:15 am
by xprimexinverse
Hi,

Apologies for reviving an old thread, but please see below my replication of the EViews built-in HP filter function using the state-space object.

It might still be of interest to some users.

Cheers,
Graeme

You can download the program here:
hpfilter_sspace_new.prg
(4.51 KiB) Downloaded 507 times

Code: Select all

' -------------------------------------------------------------------------------------------------------------------- ' DESCRIPTION: Two state-space implementations of the HP Filter. ' ' DATE: 03 / 03 / 2017 ' ' AUTHOR: Graeme Walsh ' -------------------------------------------------------------------------------------------------------------------- ' ******************************************************************************************************************** ' Pre-liminary set-up ' ******************************************************************************************************************** wfcreate(wf=example) Q 1980Q1 2017Q4 ' ******************************************************************************************************************** ' Create Simulated Data ' ******************************************************************************************************************** rndseed 123456 series e1 = nrnd series Y = 0 model AR2 AR2.append Y = 3.20 + 0.22 * Y(-1) + 0.15 * Y(-2) + e1 AR2.solveopt(s=d,d=d) AR2.solve series Y = Y_0 ' ******************************************************************************************************************* ' EViews Built-in HP Filter function ' ******************************************************************************************************************* hpf(lambda=1600,power=2) Y HPT @ HPC ' ******************************************************************************************************************** ' State-space model of HP Filter - Version 1 ' ******************************************************************************************************************** ' HP filter smoothing parameter scalar lambda = 1600 ' Create the sspace object sspace hp_mod1 ' Measurement equation hp_mod1.append @signal Y = 1 * TAU + 0 * BETA + EPS hp_mod1.append @ename EPS hp_mod1.append @evar var(EPS) = 1 ' State equation (TAU) hp_mod1.append @state TAU = 1 * TAU(-1) + 1 * BETA(-1) + ETA_TAU hp_mod1.append @ename ETA_TAU hp_mod1.append @evar var(ETA_TAU) = 0 ' State equation (BETA) hp_mod1.append @state BETA = 0 * TAU(-1) + 1 * BETA(-1) + ETA_BETA hp_mod1.append @ename ETA_BETA hp_mod1.append @evar var(ETA_BETA) = 1 / lambda ' Estimate model by maximum likelihood hp_mod1.ml ' Create state estimates hp_mod1.makestates(t=smooth) *_S1 hp_mod1.makestates(t=pred) *_P1 hp_mod1.makestates(t=filt) *_F1 ' Create gap estimates series CYCLE_S1 = Y - TAU_S1 ' Smooth gap series CYCLE_P1 = Y - TAU_P1 ' Predicted gap series CYCLE_F1 = Y - TAU_F1 ' Filtered gap ' ******************************************************************************************************************** ' State-space model of HP Filter - version 2 ' ******************************************************************************************************************** ' HP filter smoothing parameter scalar lambda = 1600 ' Create the sspace object sspace hp_mod2 ' Measurement equation hp_mod2.append @signal Y = Y_STAR + EPS hp_mod2.append @ename EPS hp_mod2.append @evar var(EPS) = 1 ' State equation (Y_STAR) hp_mod2.append @state Y_STAR = 2 * Y_STAR(-1) - 1 * Y_STAR2(-1) + ETA_Y_STAR hp_mod2.append @ename ETA_Y_STAR hp_mod2.append @evar var(ETA_Y_STAR) = 1 / lambda ' State equation (Y_STAR2) - this is called an "augmented" state variable hp_mod2.append @state Y_STAR2 = Y_STAR(-1) ' Estimate model by maximum likelihood hp_mod2.ml ' Create state estimates hp_mod2.makestates(t=smooth) *_S2 hp_mod2.makestates(t=pred) *_P2 hp_mod2.makestates(t=filt) *_F2 ' Create gap estimates series CYCLE_S2 = Y - Y_STAR_S2 ' Smooth gap series CYCLE_P2 = Y - Y_STAR_P2 ' Preditced gap series CYCLE_F2 = Y - Y_STAR_F2 ' Filtered gap ' ******************************************************************************************************************** ' Compare EViews built-in with State-Space Models ' ******************************************************************************************************************** show HPT TAU_S1 Y_STAR_S2 ' Trend comparison show HPC CYCLE_S1 CYCLE_S2 ' Cycle comparison ' ------------------------------------------------------------------------------------------------------------------- ' END OF PROGRAM ' -------------------------------------------------------------------------------------------------------------------
Edit: please note that this is not necessarily how the EViews built-in is, in fact, implemented(!) -- but my example does mimic it and retrieve the same results.