the loops of DLM model

Discussion of State Space and Dynamic Stochastic General Equilibrium Models

the loops of DLM model

Postby nkxl » Thu Nov 22, 2007 10:12 am

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

Postby TomDoan » Wed Nov 28, 2007 1:03 pm

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: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Postby nkxl » Mon Dec 03, 2007 10:37 am

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


Return to State Space Models/DSGE

Who is online

Users browsing this forum: No registered users and 1 guest