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
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.
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
Code:
' --------------------------------------------------------------------------------------------------------------------
' DESCRIPTION: State-Space implementation of 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
' ********************************************************************************************************************
' HP filter smoothing parameter
scalar lambda = 1600
' Create the sspace object
sspace hp_mod
' Measurement equation
hp_mod.append @signal y = 1 * tau + 0 * beta + eps
hp_mod.append @ename eps
hp_mod.append @evar var(eps) = 1
' State equation (tau)
hp_mod.append @state tau = 1 * tau(-1) + 1 * beta(-1) + eta_tau
hp_mod.append @ename eta_tau
hp_mod.append @evar var(eta_tau) = 0
' State equation (beta)
hp_mod.append @state beta = 0 * tau(-1) + 1 * beta(-1) + eta_beta
hp_mod.append @ename eta_beta
hp_mod.append @evar var(eta_beta) = 1 / lambda
' Estimate model by maximum likelihood
hp_mod.ml
' Create state estimates
hp_mod.makestates(t=smooth) *f1
hp_mod.makestates(t=pred) *f2
hp_mod.makestates(t=filt) *f3
' Create gap estimates
series CYCLE1 = Y-TAUF1
series CYCLE2 = Y-TAUF2
series CYCLE3 = Y-TAUF3
' ********************************************************************************************************************
' Compare EViews built-in with State-Space Model
' ********************************************************************************************************************
show HPT TAUF1 ' Trend comparison
show HPC CYCLE1 ' 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.