Page 1 of 1
Question: Dynare in a loop over a parameter space
Posted:
Fri Apr 01, 2016 2:48 pm
by Econbee
Dear Johannes,
I am trying to explore a parameter space, at each point of which I would simulate a data set. At each point, I would use Dynare to solve and simulate. The functions included the three ones in the attachment. When I run test.m, I got the following error message:
Attempt to reference field of non-structure array.
Error in set_param_value (line 22)
i = strmatch(pname,M_.param_names,'exact');
Error in test (line 11)
set_param_value('gamma_R_PI',gamma_MP(i));
Could you please help me check what the problem is?
Thank you very much!
Re: Question: Dynare in a loop over a parameter space
Posted:
Sat Apr 02, 2016 7:53 am
by jpfeifer
Please find attached the final version. The main file is
- Code: Select all
%run once to set up model and workspace
dynare test.mod noclearall;
%define grid
gamma_MP = 1.95:0.6:2.55;
gamma_FP = -0.05:0.2:0.15;
results=cell(length(gamma_MP),length(gamma_MP));
for i = 1:length(gamma_MP)
for j = 1:length(gamma_FP)
set_param_value('gamma_R_PI',gamma_MP(i));
set_param_value('gamma_tau',gamma_FP(j));
info=stoch_simul(var_list_);
if info==0
results{i,j}=oo_;
else
%model could not be solved
fprintf('model cannot be solved for gamma_R_PI=%3.2f and gamma_tau=%3.2f\n',gamma_MP(i),gamma_FP(j))
end
end
end
while the mod-file is fully functional, i.e. contains all parameters including the ones you reset later.
P.S.: Never use a Matlab-file with the same name as the Dynare file!
Re: Question: Dynare in a loop over a parameter space
Posted:
Tue Apr 05, 2016 1:09 pm
by Econbee
Dear Johannes,
That works. Thank you so much!
By the way, as I run the attached file to search for the posterior mode, I got the following error message if I use Dynare 4.4.3
Cell contents reference from a non-cell array object.
Error in dynare_estimation_init (line 64)
id = strmatch(options_.varobs{i}, M_.endo_names, 'exact');
Error in dynare_estimation_1 (line 81)
[dataset_,dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,
bayestopt_] = ...
Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);
Error in test2 (line 520)
dynare_estimation(var_list_);
Error in dynare (line 180)
evalin('base',fname) ;
If I change to the latest version of the unstable version 2016-04-04, I got the following error message
Error using check_matlab_path (line 99)
You put all the dynare/matlab subfolders in matlab's path! Only the
dynare/matlab folder (without subfolders)
should be in the path, Dynare will automatically add any required subfolders in
the path.
Error in dynare (line 60)
check_matlab_path(change_path_flag);
I get the code run successfully when I use a very old version of Dynare, which I downloaded a few years ago, version 2014-12-25.
Could you please help me check what the problem is?
Thank you!
Re: Question: Dynare in a loop over a parameter space
Posted:
Tue Apr 05, 2016 7:46 pm
by jpfeifer
I cannot replicate any issue.
To use the unstable version, you should clean your Matlab path from all Dynare-related folders and then add the Dynare/matlab folder of the unstable version to the path (not including subfolders). Note that switching Dynare versions within the same Matlab session can be problematic, because there may be subfolders added from before. Restarting Matlab or manually cleaning the path then helps.
Re: Question: Dynare in a loop over a parameter space
Posted:
Wed Apr 06, 2016 2:41 am
by Econbee
Thanks, Johannes! I followed your suggestion and got all different versions of Dynare running OK. My stable version 4.4.3 on the computer was old (downloaded in 2014). I guess there were bugs in it . I downloaded it again and it worked well now. Thank you again!