Page 1 of 1

DSGE and state space estimation

Posted: Fri Apr 08, 2011 1:50 am
by wzben
Dear all:
Im currently working on the methodology chapter of my PhD thesis. The aim is to demonstrate how to build, solve, estimate a small new Keynesian DSGE model analytically. I have a question about casting solved DSGE model into state space form. Here is my code for a three equation model:

Code: Select all

calendar(Q) 1948:4
dec series  y pi a
dec series  eps_a eps_r
dec real  beta theta sigmaL alpha rho_a kappa_pi kappa_y xi_y xi_a
compute beta = 0.98
compute theta = 0.65
compute sigmaL = 1
compute alpha = 0.4
compute rho_a = 0.9
compute kappa_pi = 1.2
compute kappa_y = 1.5
compute xi_y = ((1-beta*theta)*(1-theta)*alpha/(theta*(sigmaL + alpha)))
compute xi_a = ((1-beta*theta)*(1-theta)*sigmaL/(theta*(sigmaL + alpha)))
frml(identity) eqn1 = y  - ( y{-1} - kappa_pi*pi - kappa_y*y - eps_r)
frml(identity) eqn2 = pi  - ( beta*pi{-1} + xi_y*y + xi_a*a)
frml(identity) eqn3 = a  - ( rho_a*a{1} + eps_a)
frml           eqn4 = eps_a
frml           eqn5 = eps_r
group Mech_chap eqn1 eqn2 eqn3 eqn4 eqn5
dsge(model=Mech_chap,a=adlm,f=fdlm,z=zdlm)  y pi a  eps_a eps_r
display adlm
display fdlm
display zdlm
Where y is output gap, pi is inflation and a is technology. The model is solved in the form of:
X = A*X(1) + Z + F*w
I went through the Rats state space course, and it seems that Rats treats all variables in X as states, and map to data according to
Y = mu+ C*X +v
(chapter 12: estimation of the handbook for state space models), where C seems to be an identity matrix and apply Kalman filter to update the state variables.

All along I thought that the way to estimate a solved DSGE model is to decompose X into observable variables (that we have data, in my case is output gap and inflation) and unobservable variables(in my model is the technology). Then apply kalman filter to use information of output gap and inflation to update only the technology. I have two shocks and two series of data, so I should not have stochastic singularity problem.

The way that Rats does it seems to introduce measurement errors, but would it be the case that introduction of measurement error is to get rid of the stochastic singularity problem? Since Im not very experienced with state space models, I probably miss some obvious point...

Thank you very much for your kind help.

Cheers

Ben

Re: DSGE and state space estimation

Posted: Fri Apr 08, 2011 11:04 am
by TomDoan
If you look at the description of the Cagan model and how it's estimated:

The likelihood function can be evaluated by DLM given the system matrices. To do this, we need a C matrix to map states to observables. In this case, there will be just six states; however, in general, you don’t know before solving the model how many states needed to be added. (There will always be some if you have expectational variables). The simplest way to set up the C matrix is to first solve the model for your guess values for the parameters, then use

compute cdlm=%identity(2)˜˜%zeros(%rows(adlm)-2,2)

CDLM will take the first state as the first observable and the second as the second. For simplicity, you should arrange your variable list on DSGE to put the observables in the initial positions. The 2’s in this are the number of observables. The same will work for a different number of observables by replacing 2 in all three locations. (emphasis added)

In your case you need exactly that form for CDLM since you have two observables and you did put them in the first two slots.

Re: DSGE and state space estimation

Posted: Mon Apr 11, 2011 8:50 pm
by wzben
Hi Tom:

Thanks for your reply. I want to clarify a few points that confuse me:

1. You mentioned the number of states is 6 in the Cagan model. Does is mean the states vector includes (as in order)
1. variables claimed in 'data' and 'declare series' command
2. expectation errors
But since you know your variables before solving the model, wouldn't that mean you know the C matrix will look like (roughly)? or you mean one never know what to match before experimenting with the data since what you match does have different implication on parameters? (As in Guerron-Quintana(2010) published in Journal of Applied Econometrics).

2. After applying the Kalman filter. The cagan model has 4 data series, 4 endogenous variables and 2 shocks. Would that make the system stochastic singular since the system implies there are two identities exists in addition to the two stochastic equations?

Thank you very much for your reply and help.

Best,

Ben

Re: DSGE and state space estimation

Posted: Tue Apr 12, 2011 8:59 am
by TomDoan
wzben wrote:Hi Tom:

Thanks for your reply. I want to clarify a few points that confuse me:

1. You mentioned the number of states is 6 in the Cagan model. Does is mean the states vector includes (as in order)
1. variables claimed in 'data' and 'declare series' command
2. expectation errors
But since you know your variables before solving the model, wouldn't that mean you know the C matrix will look like (roughly)? or you mean one never know what to match before experimenting with the data since what you match does have different implication on parameters? (As in Guerron-Quintana(2010) published in Journal of Applied Econometrics).
The state vector will first have the five variables that you list on the DSGE instruction, in order. There will also be additional states required to create a standard state-space representation. For instance, if there are any second or higher lags, you need augmenting states for those. And you need states for any of the expectational variables. In this case, it appears that the only augmenting variable is for pi{-1}. By the wayt, it's not the errors, but the expectations themselves that are the added states in this representation; the expectational errors get solved out. We recommend that you solve the model once and determine the number of states by looking at the number of rows in the "A" matrix before you set up the "C" matrix so you don't have to try to figure out what the "black box" inside DSGE needs in order to complete the state-space representation.
wzben wrote: 2. After applying the Kalman filter. The cagan model has 4 data series, 4 endogenous variables and 2 shocks. Would that make the system stochastic singular since the system implies there are two identities exists in addition to the two stochastic equations?
You can only use two observables if you would like to estimate the model. There's nothing wrong with stochastic singularities for simply solving a model.

Re: DSGE and state space estimation

Posted: Tue Apr 19, 2011 11:06 pm
by wzben
Dear Tom:

Thanks for helping me out here, I do appreciate your time and effort.

I now try to estimate this model using two series of data on inflation and output gap, without measurement error. The program and data file are attached.

I found the filtered state variable, which in my case is the state of technology is almost identical to one of the data series and the most wired thing is, the estimated state variance is 0 all the way through.(I guess the signs are due to approximation error that gives very small positive or negative numbers)

I can sort of understand the state tracks one series closely because the kalman gain puts the most weight on one series over the other, but my question is, why the variance is 0?

Thank you again for your response and kind help.

Best,

Ben

Re: DSGE and state space estimation

Posted: Wed Apr 20, 2011 11:01 am
by TomDoan
Remember that the filtered state estimate is E(X(t)|t). For the two observable series (y and pi), that has to be the actual data with zero variance. If you estimate the model, the likelihood isn't based upon the filtered estimates, but on the one-step predictions, which won't be exact.

Re: DSGE and state space estimation

Posted: Wed Apr 20, 2011 4:37 pm
by wzben
Dear Tom:

Yes the filtered state is E(X(t)|t) and I have two series of data and 3 state variables. Since I do not allow any measurement error in the measurement equation, the state series for y and pi should be exactly the same as the data series, with a zero variance, of course. However, the third state, which in my case is technology a, should not have a zero variance? a is a linear combination of the observable states and shock terms, the observable states (y and pi) has a 0 variance but the shock terms has a non-trivial variance so that a should not has a 0 variance?

Thanks for your patient reply.

Cheers

Ben

Re: DSGE and state space estimation

Posted: Wed Apr 20, 2011 7:58 pm
by TomDoan
You have two shocks and two observables, so the shocks can be determined exactly once the data are observed.

Re: DSGE and state space estimation

Posted: Wed Apr 20, 2011 9:56 pm
by wzben
So can I generalise it by saying in cases when the number of observable data series coincide with the number of structural shocks, (no measurement error) all filterred states will have a 0 variance?
Sorry to bombard you with questions...Thanks in advance for your reply.
Cheers

Ben

Re: DSGE and state space estimation

Posted: Tue Apr 26, 2011 9:26 am
by TomDoan
wzben wrote:So can I generalise it by saying in cases when the number of observable data series coincide with the number of structural shocks, (no measurement error) all filterred states will have a 0 variance?
Sorry to bombard you with questions...Thanks in advance for your reply.
Cheers

Ben
Yes, given the parameters, the sequence of shocks will be exactly computable. Note, however, that the sequence of shocks depends upon the other parameters. This is similar to what happens in the linear regression: if I *know* the coefficients, then I can compute the residuals exactly.

Re: DSGE and state space estimation

Posted: Tue Apr 26, 2011 5:25 pm
by wzben
Thanks alot Tom!
Best,
Ben