On Jueves, 17 de Septiembre de 2009 18:39:31 David Hamilton escribió:
Dear Prof. Diaz-Emparanza
I greatly appreciate your taking the time to reply. I looked at the
example in the user’s guide, and I see the similarities. A few
things still confuse me, however.
Given my system and data, I have r = 2, n =1, and T = 93. My kalman
matrices should therefore have the following dimensions:
y (obsy, T x n) 93 x 1
H (obsymat, r x n) 2 x 1 : H = {1 ; 1}
R (obsvar, n x n) 1 x 1 : R = {s2}
F (statemat, r x r) 2 x 2 : F = {1, 0; 0, rho}
Q (statevar, r x r) 2 x 2 : Q = {s1, 0; 0, 0}
Do you agree?
If the model you wish is the one I wrote, with equations
x(t) = w(t) + y(t)
w(t) = w(t-1) + e(t)
y(t) = rho*y(t-1) + u(t)
I think R should be the variance of the perturbation or irregular component in
eq.1. Given that this equation does not have irrgular component, in fact you
have R={0}.
Q is the matrix of variances and covariances of the state vector [w(t),y(t)]'
so, if s1=var(w(t)) and s2=var(y(t)) and the two variables are incorrelated
Q={s1, 0; 0, s2}
...
function series loclev_sm (series y, scalar s1, scalar s2, scalar rho)
kalman
obsy y
obsymat H
statemat F
statevar Q
obsvar s1
end kalman --diffuse
series ret = ksmooth()
return ret
end function
matrix Vars = local_level(y)
muhat = loclev_sm(y, Vars[1], Vars[2], Vars[3])
This seems to work up to where the code invokes muhat, then I get
“Data error”:
Your state vector has two components, so the ksmooth() function output will be
a TX2 matrix. I think your function may be corrected in this way:
function list loclev_sm (series y, scalar s1, scalar s2, scalar rho)
kalman
obsy y
obsymat H
statemat F
statevar Q
obsvar s1
end kalman --diffuse
matrix ret = ksmooth()
series wt = ret[,1]
series yt = ret[,2]
list components = wt yt
return components
end function
the you should execute this function in this way:
list muhat = loclev_sm()
and muhat will be a list formed by two series wt and yt.
Note: I have not run this function, it may contain errors.
--
Ignacio Diaz-Emparanza
DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA)
UPV/EHU
Avda. Lehendakari Aguirre, 83 | 48015 BILBAO
T.: +34 946013732 | F.: +34 946013754
www.et.bs.ehu.es