the loops of DLM model

Discussion of State Space and Dynamic Stochastic General Equilibrium Models
nkxl

the loops of DLM model

Unread post 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?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Unread post 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.
nkxl

Unread post 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!
Post Reply