I want to overloop my .mod in dsge_varlag = [2 3 4]. After estimation command I have (I attach my files)
verbatim;
rho_grid = [2 3 4];
for i = 1:length(rho_grid)
options_.first_obs = 5;
options_.nobs = NaN;
options_.dsge_varlag = rho_grid(i);
oo_recursive_= dynare_estimation(var_list_);
options_.first_obs = 5; % It is necessary repeat this part to call dynare_estimation_init
options_.nobs = NaN; % It is necessary repeat this part to call dynare_estimation_init
[dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, bayestopt_, bounds] = ...
dynare_estimation_init(var_list_, [], [], M_, options_, oo_, estim_params_, bayestopt_);
****
end
end;
but when I run this with “dynare mymod” I see it runs four times and it should run just three times. I will repeat this process a lot of times so I need it runs just three times every time.ls.mod (6.8 KB) newmfile.m (2.6 KB)
In its current version you have the overhead of 1 execution from the initial estimation command in the mod-file before entering the loop. If you just increase the size of the loop, that fixed one additional execution is negligible. If you still want to get rid of it, you need to condition on the first run. See
Given that I need to set values of dsge_varlag I am looking for a function similar to set_param_value that works with dsge_varlag. Is there some way or recommendation to create this function?
The snippet you posted is not a good idea, because you would run the Dynare preprocessor in every iteration. Dynare should only be run in the first iteration. Within the mod-file, you simply hardcode the first value of the parameter
dsge_varlag is not a parameter. Therefore no similar function is available. Changing it requires quite intensive recomputations like the empirical moments. The way you programmed this was right.