On Fri, 21 Aug 2015, Sven Schreiber wrote:
Am 21.08.2015 um 16:37 schrieb Fernando Fernandes Neto:
> Dear Sven,
>
> Thanks a lot for your attention.
> What you've commented makes a lot of sense to me. So actually, I would
> have a vector of Time Varying Coefficients (that would be my exogenous
> variables), and a vector of unitary constants, being added to the State?
>
Forget my remark about the constant, that was probably off-track. What I
have in mind is more or less the following.
Yeah, Sven's approach is very sensible and arguably the most natural. What
follows is an example script in which I simulate and estimate a model like
this:
y_t = alpha_t + epsilon_t
alpha_t = x_t + 0.5*alpha_{t-1} + u_t
which is more or less like the example Sven suggested, with y_t and x_t
are observable series, epsilon_t and u_t are wn processes, and alpha_t is
the latent state variable.
I guess you can adapt it to your needs relatively easily.
<hansl>
set echo off
set messages off
/*
generate some data
*/
nulldata 256
set seed 21082015 # make things replicable
setobs 1 1 --special-time-series
series exo = 5
exo = 1 + 0.8 * exo(-1) + normal() # this could be anything, really
series alpha = 10
series u = 0.5*normal()
series e = 0.2*normal()
alpha = exo + 0.5*alpha(-1) + u
series y = alpha + e
/*
set up the state space model
*/
function void TV_statemat(matrix *F, matrix x)
F[1,2] = x[$kalman_t]
end function
matrix mexo = {exo}
scalar se = 0.5
scalar su = 0.7
matrix H = {1;0}
matrix F = {1, 1; 0, 1}
matrix Omega = {1,0;0,0}
matrix a0 = {0; 1}
matrix P0 = {1.0e12, 0; 0, 0}
kalman
obsy y
obsymat H
obsvar su
statemat F ; TV_statemat(&F, mexo)
statevar Omega
inistate a0
inivar P0
end kalman
/*
now estimate
*/
matrix param = {0.5, 1, 1}
matrix ahat
series LL = 0
mle LL = err ? NA: $kalman_lnl
su = param[2]^2
Omega[1,1] = param[3]^2
F[1,1] = param[1]
err = kfilter()
params param
end mle -vh
ahat = ksmooth()
series latent_est = ahat[,1]
print alpha latent_est -o
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------