Code can work but need more than 15 hours!

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Code can work but need more than 15 hours!

Postby Grant » Tue Jun 10, 2014 3:28 pm

Dear,

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 ?

Regards,

Code: Select all
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;
Grant
 
Posts: 95
Joined: Tue Jun 10, 2014 2:37 pm

Re: Code can work but need more than 15 hours!

Postby jpfeifer » Wed Jun 11, 2014 9:10 pm

Please post the mod-files and the data. Otherwise, it is impossible to tell what is going on.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Code can work but need more than 15 hours!

Postby Grant » Thu Jun 12, 2014 1:55 am

Dear,

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.

Regards,
Attachments
model_data.xls
(46.5 KiB) Downloaded 236 times
code.mod
code
(12.97 KiB) Downloaded 249 times
Grant
 
Posts: 95
Joined: Tue Jun 10, 2014 2:37 pm

Re: Code can work but need more than 15 hours!

Postby jpfeifer » Thu Jun 12, 2014 6:29 am

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
Code: Select all
epsd_stern4aux = epsd_stern4;
epsd_stern8aux = epsd_stern8;


Given the size of your model and the few observables, run
Code: Select all
identification(ar=10);

to see that you cannot identify all the parameter you try to estimate:
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!]



WARNING !!!
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!]
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Code can work but need more than 15 hours!

Postby Grant » Thu Jun 12, 2014 6:47 am

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?

Regards,
Grant
 
Posts: 95
Joined: Tue Jun 10, 2014 2:37 pm

Re: Code can work but need more than 15 hours!

Postby jpfeifer » Thu Jun 12, 2014 7:00 am

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" https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Code can work but need more than 15 hours!

Postby Grant » Thu Jun 12, 2014 7:33 am

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 ?

Regards'
Grant
 
Posts: 95
Joined: Tue Jun 10, 2014 2:37 pm

Re: Code can work but need more than 15 hours!

Postby jpfeifer » Thu Jun 12, 2014 7:51 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Code can work but need more than 15 hours!

Postby Grant » Thu Jun 12, 2014 8:17 am

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.

Regards'
Attachments
code.mod
(12.87 KiB) Downloaded 168 times
Grant
 
Posts: 95
Joined: Tue Jun 10, 2014 2:37 pm

Re: Code can work but need more than 15 hours!

Postby jpfeifer » Thu Jun 12, 2014 8:26 am

See Remark 16 (Nested model-local variables and nested parameters)
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Code can work but need more than 15 hours!

Postby Grant » Thu Jun 12, 2014 11:11 am

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 " viewtopic.php?f=1&t=202 ". It seems that
Code: Select all
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.

Regards,
Attachments
usdata54aspextrev.m
(17.4 KiB) Downloaded 175 times
Khan.mod
(16.85 KiB) Downloaded 181 times
code.mod
(12.86 KiB) Downloaded 183 times
Grant
 
Posts: 95
Joined: Tue Jun 10, 2014 2:37 pm

Re: Code can work but need more than 15 hours!

Postby jpfeifer » Thu Jun 12, 2014 6:16 pm

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Code can work but need more than 15 hours!

Postby Grant » Fri Jun 13, 2014 8:02 am

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
Code: Select all
// 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?

Regards,
Grant
 
Posts: 95
Joined: Tue Jun 10, 2014 2:37 pm

Re: Code can work but need more than 15 hours!

Postby jpfeifer » Mon Jun 16, 2014 9:11 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare contributions and examples

Who is online

Users browsing this forum: No registered users and 5 guests