the loops of DLM model
-
nkxl
the loops of DLM model
I want to estimate the following model with Kalman filter for 25 betas:
Y(t)-a0=X(t)+v(t)
X(t)=a1*X(t-1)+w(t).
I tried to use loop as follows
dofor i = beta11 to beta55
stat(noprint) i
com vary=%variance
nonlin a0 a1 varv
com varv=0.01
com a0=0.1
com a1=0.9
dlm(a=a1, y=i-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs)
end dofor
But the results are not right. But when I do it one by one, I can get sensible results such as
stat(noprint) beta11
com vary=%variance
nonlin a0 a1 varv
com varv=0.01
com a0=0.1
com a1=0.9
dlm(a=a1, y=beta11-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs)
stat(noprint) beta12
com vary=%variance
nonlin a0 a1 varv
com varv=0.01
com a0=0.1
com a1=0.9
dlm(a=a1, y=beta12-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs)
and so on
Could someone help me where I am wrong?
Y(t)-a0=X(t)+v(t)
X(t)=a1*X(t-1)+w(t).
I tried to use loop as follows
dofor i = beta11 to beta55
stat(noprint) i
com vary=%variance
nonlin a0 a1 varv
com varv=0.01
com a0=0.1
com a1=0.9
dlm(a=a1, y=i-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs)
end dofor
But the results are not right. But when I do it one by one, I can get sensible results such as
stat(noprint) beta11
com vary=%variance
nonlin a0 a1 varv
com varv=0.01
com a0=0.1
com a1=0.9
dlm(a=a1, y=beta11-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs)
stat(noprint) beta12
com vary=%variance
nonlin a0 a1 varv
com varv=0.01
com a0=0.1
com a1=0.9
dlm(a=a1, y=beta12-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs)
and so on
Could someone help me where I am wrong?
Try using the following in the loop:
This replaces "i" in the y calculation (which will be interpreted as an integer) with i{0}, which will be the current value of series i.
Code: Select all
dlm(a=a1, y=i{0}-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs) -
nkxl
Thanks a lot Tom! It does work very well!TomDoan wrote:Try using the following in the loop:
This replaces "i" in the y calculation (which will be interpreted as an integer) with i{0}, which will be the current value of series i.Code: Select all
dlm(a=a1, y=i{0}-a0, c=1.0, sx0=vary-varv, $ sw=(1-a1**2)*(vary-varv),sv=varv,method=bfgs)