Hi community!
I'm trying to compute a time-varying state space model to calculate stocks' betas. Unfortunately, I have some missing observations and, when this is the case, the model implemented by Gretl suddenly stops and doesn't compute anything (as expected). My question is simple: Is there a way of instructing Gretl to ignore missing values and compute the state spacel model?
Here is the example code taken from chapter 35 of Gretl manual. Please note that I added line 6 "INFQ[20] = NA" in order to have a missing data point in the data.
<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
INFQ[20] = NA # added this line to have a missing value
/* 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>
Best,
Filipe