Page 1 of 1
Getting errors from matlab after running dynare
Posted:
Thu Dec 05, 2013 2:03 am
by Victor
I run a code from matlab to run dynare with some parameters. If I run this code with initial parameters, it runs fine but once I change these parameters I get error 'Index matrix exceed dimension' with a report on the psi matrix I formed
A=oo_.dr.ghx;
E=oo_.dr.ghu;
nvar=size(oo_.dr.order_var);
D=[zeros(nvar,oo_.dr.nstatic) A(:,1:oo_.dr.npred) zeros(nvar,oo_.dr.nfwrd)];
The D matrix being the error. These matrix is extracted from the oo_ output created by dynare first order condition.
Re: Getting errors from matlab after running dynare
Posted:
Thu Dec 05, 2013 1:41 pm
by jpfeifer
It seems you are trying to loop over Dynare without catching errors. If your parameter draw is invalid, the respective fields of oo_ will not be set. Try using a try-catch statement or get the return code of stoch_simul. See also
http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4891
Re: Getting errors from matlab after running dynare
Posted:
Sun Dec 08, 2013 10:09 pm
by Victor
I was able to follow the link's step you gave but all methods proved abortive. What I understand is that the ghx returns empty after some iterations and that is when I get the error.
Re: Getting errors from matlab after running dynare
Posted:
Mon Dec 09, 2013 9:23 am
by jpfeifer
You are trying to run
- Code: Select all
stoch_simul (noprint,nofunctions,nomoments,nocorr,irf=0);
A=oo_.dr.ghx;
E=oo_.dr.ghu;
nvar=size(oo_.dr.order_var);
D=[zeros(nvar,oo_.dr.nstatic) A(:,1:oo_.dr.npred) zeros(nvar,oo_.dr.nfwrd)];
This results in
- Code: Select all
info = stoch_simul(var_list_);
A=oo_.dr.ghx;
E=oo_.dr.ghu;
nvar=size(oo_.dr.order_var);
D=[zeros(nvar,oo_.dr.nstatic) A(:,1:oo_.dr.npred) zeros(nvar,oo_.dr.nfwrd)];
in the m-file. What you want to do is check whether info==0, which is the code for the model solving correctly. If info~=0, the respective fields will not be set.
For your purpose, I recommend using a combination of set_param_value and stoch_simul as at the mentioned link. You are already trying to directly work on the m-files and by executing the whole m-file instead of just the parts you need you are slowing the code down. Note that at the beginning of the linked page you can also see a construction that checks for the indicator info.
Re: Getting errors from matlab after running dynare
Posted:
Mon Dec 09, 2013 12:11 pm
by Victor
how do I check info==0 or info~=0? from dynare output I see info=0 and it is same as you posted in the m-file. As regarding the set_param_value, I keep getting error because the pname I enter doesn't exist. My parameters are in one folder so I try entering the folder's name, or do I have to write for each? Lastly, I'm a bit confused in the set-up as well, do I set_param_value using rho or the parameters (as in my case that is what I am looking to change)? Thank you in advance
Re: Getting errors from matlab after running dynare
Posted:
Mon Dec 09, 2013 12:22 pm
by Victor
[for i = 1:1000
set_param_value('coef',coef(i))
[dr,~,M,~,oo] = resol(0,M_,options_,oo_);
y_ = simult_(oo_.steady_state,dr,oo_.exo_simul,1);
storey(i) = y_;
end
shock_mat=randn(D,1000);]
Please see how I set it up. coef is my parameter file. The shock_mat was able to run but the loop was not. Thanks
Re: Getting errors from matlab after running dynare
Posted:
Tue Dec 10, 2013 10:48 am
by jpfeifer
Checking for info can be done by using
- Code: Select all
if info==0;
A=oo_.dr.ghx;
E=oo_.dr.ghu;
nvar=size(oo_.dr.order_var);
D=[zeros(nvar,oo_.dr.nstatic) A(:,1:oo_.dr.npred) zeros(nvar,oo_.dr.nfwrd)];
else
whatever you want to filter out this case
end;
Note that info is the second output argument of resol, which you are currently suppressing.
The set_param_value command takes as inputs first the Dynare name of the parameter and then the value:
- Code: Select all
set_param_value('coef',coef(i))
thus sets the parameter named coef to the value stored in coef(i). If you want to set more parameters in a loop, you can use a cell array with the parameter names and the eval-command, see
http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4437Finally, note that the oo_.exo_simul used in the simult_-command was wrong as detailed in the original post.
Re: Getting errors from matlab after running dynare
Posted:
Tue Dec 10, 2013 2:49 pm
by Victor
I tried that but matlab tells me coef is not a parameter, I just can't figure out how the link is related to what i'm doing. Anyway, I have come to understand the problem is from dynare 4.3.3. so I reverted to to dynare 3.6.4. all is good now. I will post you a link of my codes soon. Thank you.
Re: Getting errors from matlab after running dynare
Posted:
Tue Dec 10, 2013 6:16 pm
by Victor
by the way, I regret to say but, I tried all avenues but nothing seems to work. I guess I will give up on the questions I have. I will try other avenues for solution.