Page 1 of 1

the loops of DLM model

Posted: Thu Nov 22, 2007 9:12 am
by nkxl
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?

Posted: Wed Nov 28, 2007 12:03 pm
by TomDoan
Try using the following in the loop:

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) 
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.

Posted: Mon Dec 03, 2007 9:37 am
by nkxl
TomDoan wrote:Try using the following in the loop:

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) 
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.
Thanks a lot Tom! It does work very well!