Code can work but need more than 15 hours!


I am a new learner about Dynare. I have encountered a question now and am seeking for your help. I developed a DSGE model with multiple unanticipated and news shocks, and I use Bayesian estimation to estimate the value of some parameters and assign the value to some other parameters using calibration. My code can work in Dynare but it has been working for more than 15 hours! So I think there must be something wrong with my code. Can you help me with this problem? I really appreciate your help!

PS: I found that as long as I remove the news shocks, my code can work very well and got a result within a reasonable time. So I guess that it may be due to the news shocks. Since I have only six observables but much more parameters and shocks, do I need to use more observables in order to speed up my code working process ?


estimation(datafile=model_data, mode_compute = 6, nograph, mh_nblocks = 4, mh_replic=20000, mh_drop=0.04,mh_jscale=0.28, conf_sig=0.95, bayesian_irf)y n pi_d_h pi_c r c c_b c_s psi d_b d_s b_b y_c y_d i_d;

Please post the mod-files and the data. Otherwise, it is impossible to tell what is going on.


Thanks for your relply! Here attached my code and data.

BTW, sometimes dynare shows that “The rank conditions ISN’T verified!” but it still can run. What’s the problem? I am looking forward for your answer. Thanks in advance.

model_data.xls (46.5 KB)
code.mod (13 KB)

Your model is just big. News shocks augment the state space and you end up with almost 200 equations. One likelihood evaluation takes 1 second. In this case, mode finding will take forever, but there is not much you can do except for waiting. You could try to get rid of redundant equations like

epsd_stern4aux = epsd_stern4; epsd_stern8aux = epsd_stern8;

Given the size of your model and the few observables, run

to see that you cannot identify all the parameter you try to estimate:

[quote]WARNING !!!
The rank of H (model) is deficient!

epsd_stern is not identified in the model!
[dJ/d(epsd_stern)=0 for all tau elements in the model solution!]
theta_d is not identified in the model!
[dJ/d(theta_d)=0 for all tau elements in the model solution!]
theta_c is not identified in the model!
[dJ/d(theta_c)=0 for all tau elements in the model solution!]

The rank of J (moments) is deficient!

epsd_stern is not identified by J moments!
[dJ/d(epsd_stern)=0 for all J moments!]
epsd_stern8 is not identified by J moments!
[dJ/d(epsd_stern8)=0 for all J moments!]
rho_d_stern is not identified by J moments!
[dJ/d(rho_d_stern)=0 for all J moments!]
theta_d is not identified by J moments!
[dJ/d(theta_d)=0 for all J moments!]
theta_c is not identified by J moments!
[dJ/d(theta_c)=0 for all J moments!][/quote]

Dear Pfeifer,

Thanks for your kindly answer. Since my model is so big with a large number of parameters and few observables, can I increase the observable to solve this problem?


If a parameter is not identified in the model at all, observables won’t help. They also won’t speed up estimation.
Looking at your model, I found the source for this problem. For estimation, you cannot define kappa_d as an independent parameter (similar for the steady state values defined outside of the model block). Please see Remark 4 (Parameter dependence and the use of model-local variables) in Please see Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”

Dear Pfeifer,

Thanks for your kindly reply! It indeed is a great help for me. Do you mean I need to define some of the parameters such as “kappa_c” and the equilibrium values in the model block using the # -operator ?


Yes. Every object that depends on parameters that are estimated needs to be defined as a model local variable (#) or updated in a steady state file.

Dear Pferifer,

Thanks for your great help. I have modified my code that I put the parameters and equilibrium values into the model block using the #-operator. But Dynare shows an error “ERROR: code.mod: line 85, cols 31-32: Unknown symbol: ND”. I actually have defined NC in the model. Could you help me with this problem?

Here attached my updated code.

code.mod (12.9 KB)

See Remark 16 (Nested model-local variables and nested parameters)

Dear Pfeifer,

Many thanks for your help! I have rectified my code and here attached again. However, even though the code can work now, the original problem still exists, which is “The rank condition ISN’T verified!”, and it seems to need a really long time to run. What’s the problem? Does it mean that there is something wrong with my model?

As the issue about news shock in my code, I just followed the " Unrealized expectations ". It seems that epsd_stern4aux = epsd_stern4; epsd_stern8aux = epsd_stern8; is not redundant. And I also referred to the code of Khan and Tsoukalas (2012), whose paper mainly studies the news shocks. Here attached Khan’ code as well.

In addition, since I have manually-derived steady state conditions which is shown as “EQUILIBRIUM VALUES” in my code, can I use the “steady_state_model” command or write a separate steady state file to speed up the code running process ?

And I use Bayesian to estimate some parameters and assign the value to some other parameters using calibration, I am a bit confused about the parameters block. What’s the difference of the value assigned to the estimated parameters between the value in parameters block and the estimated_params block ? I think the estimated_params block has already contains the initial value, prior mean, prior s.d. .

I am looking forward for your reply.

usdata54aspextrev.m (17.4 KB)
Khan.mod (16.8 KB)
code.mod (12.9 KB)

For the rank conditions problem, what did you change compared to the first version of the code that ran? All parameters should be the same as in the first version when you enter stoch_simul.

The post you refer to is really old. You don’t need those auxiliary variables anymore. Dynare does that for you. See the news shock example on my homepage.

A steady state file won’t help, because all steady state values of the model variables are 0. You are providing parameters in your “EQUILIBRIUM VALUES”. Let me repeat my point: your model implies a state transition matrix of 197 by 197. The matrix inversion in the Kalman filter will take up most of the time and there is nothing you can do about this except for making your model smaller.

Dynare will take the parameterization before the model-block as the starting point and keep those parameters at their values unless they are estimated using the estimated_params-block. Hence, everything you do not estimate is fixed at those values. See Remark 2 (Using stoch_simul before Estimation) in my guide.

Dear Pfeifer,

Many thanks for your help!

I have realized that the value of parameters that need to be estimated has to be assigned in the parameter-block, whose assigned value is the “most likely” I think, not the initial value or prior mean, am I right ?

In addition, I have no idea about your news shock code// set shocks for pure news shock_matrix(1,strmatch('eps_z_news',M_.exo_names,'exact')) = 1; %set news shock to 1 (use any shock size you want) shock_matrix(1+8,strmatch('eps_z_surprise',M_.exo_names,'exact')) = -1; %8 periods later use counteracting shock of -1. Because I found that even I remove the above block, the code can still work, the policy and transition function can still show eps_z_news in total 8 periods, and the IRF seem to be no difference. Could you explain about this block?


The block you are referring to is just for plotting a “pure news shocks”, i.e. an anticipated shock that never realizes. It has nothing to do with how you specify or estimate your model.