## the loops of DLM model

Discussion of State Space and Dynamic Stochastic General Equilibrium Models

### 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?
nkxl

Posts: 4
Joined: Tue Oct 30, 2007 11:54 am

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

Posts: 2760
Joined: Wed Nov 01, 2006 5:36 pm

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!
nkxl

Posts: 4
Joined: Tue Oct 30, 2007 11:54 am

### Who is online

Users browsing this forum: No registered users and 0 guests