Question: Dynare in a loop over a parameter space

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)

Could you please help me check what the problem is?

Thank you very much!
test_steadystate.m (3.51 KB)
test.mod (12.1 KB)
test.m (321 Bytes)

Please find attached the final version. The main file is

%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;

for i = 1:length(gamma_MP)
    for j = 1:length(gamma_FP)
        if info==0
            %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))

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!
Loop_main.m (690 Bytes)
Loop_example.mod (14.3 KB)

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)
Error in test2 (line 520)
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)

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!
mydata.xls (65.5 KB)
test2.mod (15 KB)

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.

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!