Dear All,
I'm in trouble with state space models, as I find them difficult to implement. I was
able to set up a few with just one time-variant unobservable variable but I'm not sure
on what I'm doing when there are more. Let's say we depart from the example of the
Phillips curve on pages 345-346 of Gretl manual, where the inflation rate (INFQ) depends
on the unemployment rate (URX). In the example, the intercept is time-invariant and the
coefficient for URX follows a random walk.
Let's expand the model such that there is a second independent variable Effective
Exchange Rate (EER) explaining INFQ. Additionally, I want all three coefficients to follow
an AR(1) process. The image attached shows this new model. How hard would that be to
implement these changes on the script depicted on manual page 347 (as follows):
<hansl>
function void at_each_step(bundle *b)
b.obsymat = transp(b.mX[b.t,])
end function
open AWM.gdt --quiet
smpl 1974:1 1994:1
/* parameter initialization */
scalar b0 = mean(INFQ)
scalar s_obs = 0.1
scalar s_state = 0.1
/* bundle setup */
bundle B = ksetup(INFQ, 1, 1, 1)
matrix B.mX = {URX}
matrix B.depvar = {INFQ}
B.timevar_call = "at_each_step"
B.diffuse = 1
/* ML estimation of intercept and the two variances */
mle LL = err ? NA : B.llt
B.obsy = B.depvar - b0
B.obsvar = s_obs^2
B.statevar = s_state^2
err = kfilter(&B)
params b0 s_obs s_state
end mle
/* display the smoothed time-varying slope */
ksmooth(&B)
series tvar_b1hat = B.state[,1]
series tvar_b1se = sqrt(B.stvar[,1])
gnuplot tvar_b1hat --time-series --with-lines --output=display \
--band=tvar_b1hat,tvar_b1se,1.96 --band-style=fill
</hansl>
--
F.R.Costa