Puzzle for speculative bubbles using state space

Discussion of State Space and Dynamic Stochastic General Equilibrium Models
xiangyu71
Posts: 9
Joined: Thu Apr 01, 2010 4:52 am

Puzzle for speculative bubbles using state space

Unread post by xiangyu71 »

i'm try to code for speculative bubbles using state space, but i don't know how to organize the data and how to perform the program.

In model the state variable "dt" is observed and state variable "bt" is unobserved. the model is the attached paper

thanks in advanced!

best regards.
Last edited by xiangyu71 on Sun Apr 11, 2010 2:38 am, edited 4 times in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Puzzle for speculative bubbles using state space

Unread post by TomDoan »

The A matrix is set up with:

dec frml[rect] af
frml af = ||phi1,phi2,phi3,0,0,0|$
1,0,0,0,0,0|$
0,1,0,0,0,0|$
0,0,1,0,0,0|$
0,0,0,0,1/psi,0|$
0,0,0,0,1,0||

The "F" matrix is the fixed matrix

dec rect f(6,2)
input f
1 0
0 0
0 0
0 0
0 1
0 0

The "C" matrix (which is the transpose of the matrix in 12.24 is represented with

dec frml cf
frml cf = ||(1+m1),1|$
m2-m1,0|$
m3-m2,0|$
-m3,0|$
1,0|$
-1,0||

You don't have an SV, since the measurement equation has no error. SW is a diagonal matrix. It looks as if the m's are a function of other parameters, you so need to define a function which computes them and include it as a START option, that is:

function CalcM
stuff to compute m1,m2,m3
end CalcM

The DLM instruction will then be:

dlm(start=CalcM(),a=af,c=cf,f=f,sw=%diag(||sigdeltasq,sigetasq||),y=||dp,dd||,other options)
xiangyu71
Posts: 9
Joined: Thu Apr 01, 2010 4:52 am

Re: Puzzle for speculative bubbles using state space

Unread post by xiangyu71 »

thanks very much!!
Last edited by xiangyu71 on Tue Apr 06, 2010 9:40 am, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Puzzle for speculative bubbles using state space

Unread post by TomDoan »

xiangyu71 wrote:i understand some about it . but i still have some question as fellows:

(1) the parameter M=c(m1,m2,m3) is obtained by the parameters PHI and psi. should i give the initiated value c(phi1,phi2,phi3,psi) to calculated M=c(m1,m2,m3) firstly? Must I give a loop to update m=c(m1,m2,m3) and how can i ?
(2)Whether should the data (△dt △dt-1 △dt-2 △dt-3 △bt △bt-1) in state equation and measure equation be setting(should the data △dt △dt-1 △dt-2 △dt-3 be stacked?) or not? is the data organized by formulation or program automatically?

my programm


dec frml[rect] af
frml af = ||phi1,phi2,phi3,0,0,0|$
1,0,0,0,0,0|$
0,1,0,0,0,0|$
0,0,1,0,0,0|$
0,0,0,0,1/psi,0|$
0,0,0,0,1,0||

dec rect f(6,2)
input f
1 0
0 0
0 0
0 0
0 1
0 0

dec frml cf
frml cf = ||(1+m1),1|$
m2-m1,0|$
m3-m2,0|$
-m3,0|$
1,0|$
-1,0||

dec frml[rect] phi
frml phi = ||phi1,phi2,phi3|$
1,0,0|$
0,1,0|$
0,0,1||

decl frml [vect] CalcM

com CalcM = ee*psi*INV(%identity(3)-psi*phi))

nonlin m1 m2 m3

frml m1 = CalcM(1,1)
frml m2 = CalcM(1,2)
frml m3 = CalcM(1,3)

dec vect ee
ee = ||1,0,0||

compute phi1=phi2=phi3=0.1

dlm(start=CalcM(),method=bfgs,a=af,c=cf,f=f,sw=%diag

(||sigdeltasq,sigetasq||),y=||dlnrsi,dlnrgl||,TYPE=FILTER)


the error message :
## I2. Expected Instruction Here
>>>>(<<<<

the closed is full paper

thanks very much!!
First: your definition of phi has the wrong dimensions. It should be 3 x3 , not 4 x 3. You want to get rid of that last row.

Code: Select all

dec frml[rect] phi
frml phi = ||phi1,phi2,phi3|$
1,0,0|$
0,1,0||
Your m1, m2 and m3 aren't part of your parameter set since they're derived from the phi's and psi, so you don't want them in the nonlin. The following will calculate the m vector and define the m1, m2 and m3.

Code: Select all

function CalcM
dec vector CalcM
com CalcM = %xcol(psi*INV(%identity(3)-psi*phi(1)),1)
compute m1=CalcM(1)
compute m2=CalcM(2)
compute m3=CalcM(3)
end CalcM
Your nonlin should be

Code: Select all

nonlin phi1 phi2 phi3 sigdeltasq sigetasq (and psi as well if that's a free parameter)
You'll have to give guess values to the variances.

That final error, though seems to be because the DLM instruction wrapped to the next line without a continuation. It should read like:

Code: Select all

dlm(start=CalcM(),method=bfgs,a=af,c=cf,f=f,$
  sw=%diag(||sigdeltasq,sigetasq||),y=||dlnrsi,dlnrgl||,TYPE=FILTER)


I don't see any simple way to reduce the number of states in the model.
xiangyu71
Posts: 9
Joined: Thu Apr 01, 2010 4:52 am

Re: Puzzle for speculative bubbles using state space

Unread post by xiangyu71 »

TomDoan wrote:
xiangyu71 wrote: I don't see any simple way to reduce the number of states in the model.
states determinated by lags of VAR, isn't it? how can i reduce the number of states?
Last edited by xiangyu71 on Mon Apr 05, 2010 1:39 pm, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: continue to Puzzle for speculative bubbles using state space

Unread post by TomDoan »

That's not a particularly large model, so I wouldn't worry about it taking too long to run. While it's certainly possible to generalize it to n lags rather than hard coding it for 3, I would recommend getting it to work for the fixed number of lags first, then worry about generalizing later.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Puzzle for speculative bubbles using state space

Unread post by TomDoan »

xiangyu71 wrote:

Code: Select all

nonlin phi1 phi2 phi3 sigdeltasq sigetasq psi
compute phi1= phi2= phi3= sigdeltasq =sigetasq =psi=0.1
sw=%diag(||sigdeltasq,sigetasq||)
That last line shouldn't be there.
xiangyu71
Posts: 9
Joined: Thu Apr 01, 2010 4:52 am

Re: continue to Puzzle for speculative bubbles using state space

Unread post by xiangyu71 »

TomDoan wrote:That's not a particularly large model, so I wouldn't worry about it taking too long to run. While it's certainly possible to generalize it to n lags rather than hard coding it for 3, I would recommend getting it to work for the fixed number of lags first, then worry about generalizing later.
thanks for your recommend to me!
there are still some question about program

when i run the prog as fellows:
thanks very much!
Last edited by xiangyu71 on Tue Apr 06, 2010 9:41 am, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: [Urgency] Puzzle for speculative bubbles using state space

Unread post by TomDoan »

Please send the program and data to support@estima.com. At this point, your problems are too specific to your particular situation to keep trying to answer them on the forum.
xiangyu71
Posts: 9
Joined: Thu Apr 01, 2010 4:52 am

Re: [Urgency] Puzzle for speculative bubbles using state space

Unread post by xiangyu71 »

TomDoan wrote:Please send the program and data to support@estima.com. At this point, your problems are too specific to your particular situation to keep trying to answer them on the forum.
i have sent the program and data to support@estima.com

i'm really thanks for your patients
xiangyu71
Posts: 9
Joined: Thu Apr 01, 2010 4:52 am

Re: [Urgency] Puzzle for speculative bubbles using state space

Unread post by xiangyu71 »

TomDoan wrote:Please send the program and data to support@estima.com. At this point, your problems are too specific to your particular situation to keep trying to answer them on the forum.
OPEN DATA "C:\data\133.xls"
CALENDAR(M) 1991:4
ALL 2010:03
DATA(FORMAT=XLS,ORG=COLUMNS) 1991:04 2010:03 rsi rgl date lnrsi lnrgl dlnrsi dlnrgl
OPEN DATA "C:\data\133.xls"

nonlin phi1 phi2 phi3 psi
compute phi1=0.1, phi2=0.1, phi3= 0.1,psi=0.1

dec frml[rect] af
frml af = ||phi1,phi2,phi3,0,0,0|$
1,0,0,0,0,0|$
0,1,0,0,0,0|$
0,0,1,0,0,0|$
0,0,0,0,1/psi,0|$
0,0,0,0,1,0||

dec rect f(6,2)
input f
1 0
0 0
0 0
0 0
0 1
0 0

function CalcM1
dec vector CalcM1
compute CalcM1 = %xcol(psi*INV(%identity(3)-psi*phi(1)),1)
compute m1=CalcM1(1)
compute m2=CalcM1(2)
compute m3=CalcM1(3)
end CalcM1

dec frml cf
frml cf = ||(1+m1),1|$
m2-m1,0|$
m3-m2,0|$
-m3,0|$
1,0|$
-1,0||

dec frml[rect] phi
frml phi = ||phi1,phi2,phi3|$
1,0,0|$
0,1,0||

nonlin phi1 phi2 phi3 sigdeltasq sigetasq psi

compute sigdeltasq =0.1,sigetasq =0.1,psi=0.1,$
sw=%diag(||sigdeltasq,sigetasq||)

dlm(start=CalcM1(),method=bfgs,a=af,c=cf,f=f, $
sw=%diag(||sigdeltasq,sigetasq||), y=||dlnrsi,dlnrgl||,TYPE=FILTER)

when i run it ,the error message :
## SX1. Identifier CALCM1 is Already in use as a(n) User Function

i want to know what problem will be exist in my programm!
thanks
moderator
Site Admin
Posts: 269
Joined: Thu Oct 19, 2006 4:33 pm

Re: Puzzle for speculative bubbles using state space

Unread post by moderator »

We're already handling this via email--let's not waste other people's time posting the same question here, OK?

Thanks,
Tom Maycock
xiangyu71
Posts: 9
Joined: Thu Apr 01, 2010 4:52 am

Re: Puzzle for speculative bubbles using state space

Unread post by xiangyu71 »

moderator wrote:We're already handling this via email--let's not waste other people's time posting the same question here, OK?

Thanks,
Tom Maycock
sorry,thanks!
Post Reply