Question: Dynare in a loop over a parameter space

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.

Question: Dynare in a loop over a parameter space

Postby Econbee » Fri Apr 01, 2016 2:48 pm

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!
Attachments
test_steadystate.m
(3.51 KiB) Downloaded 88 times
test.mod
(12.12 KiB) Downloaded 110 times
test.m
(321 Bytes) Downloaded 96 times
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am

Re: Question: Dynare in a loop over a parameter space

Postby jpfeifer » Sat Apr 02, 2016 7:53 am

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!
Attachments
Loop_main.m
Main Matlab file containing the loop
(690 Bytes) Downloaded 149 times
Loop_example.mod
mod-file to be looped over
(14.31 KiB) Downloaded 159 times
------------
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: Question: Dynare in a loop over a parameter space

Postby Econbee » Tue Apr 05, 2016 1:09 pm

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!
Attachments
mydata.xls
(65.5 KiB) Downloaded 103 times
test2.mod
(14.98 KiB) Downloaded 93 times
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am

Re: Question: Dynare in a loop over a parameter space

Postby jpfeifer » Tue Apr 05, 2016 7:46 pm

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.
------------
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: Question: Dynare in a loop over a parameter space

Postby Econbee » Wed Apr 06, 2016 2:41 am

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!
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 14 guests