Question about updating parameter values

As suggested in many posts, to update the parameter values in a model with Dynare, I run the .mod first and then use

dynare MY_FILE.mod
set_param_value('para name', -the value-);
info(var_list_)
% results wanted

My question is that, if I don’t randomize the seed in MY_FILE.mod, will Dynare give me the same simulation results when the updated value is the same as before? For example, alpha = 0.7 in the original file and then I ‘update’ the value of alpha to 0.7 using the above code.

In practice, I didn’t get the same simulation results and I’m wondering why. Is the reason that Dynare updates the randomness generating process on the back end (again I didn’t set random seeds here)? Because if all the information other than the parameter value remains the same, I don’t see why the results can be different.

Thank you very much in advance.

You need to state clearly what you are actually doing. I infer that your are running simulations. Simulations on a computer never result in the same results unless you fix the seed of the random number generator. That seems to be what you want to do. In this case, use

set_dynare_seed('default');

before running a new simulation.

Sorry I know questions of ''looping over parameters" have been raised over and over, but I still feel a little confused. For example, now I have the following fraction of codes. (If you need codes, I’ll attach them). In exercise.m file:

global RHO_A RHO_R RHO_RF RHO_YF RHO_P RHO_Y RHO_E;
global params;

RHO_A      = 0.9;    
RHO_R      = 0.0;  
RHO_RF     = 0.9; 
RHO_YF     = 0.9; 
RHO_P      = 1.5;
RHO_Y      = 0.5;  
RHO_E      = 0.0; 

params = [RHO_A; RHO_R; RHO_RF; RHO_YF; RHO_P; RHO_Y; RHO_E];

save parametervalues ...
RHO_A RHO_R RHO_RF RHO_YF RHO_P RHO_Y RHO_E;
save params;

dynare Loop.mod noclearall

In Loop.mod,

load params;
set_param_value('RHO_A',RHO_A);
set_param_value('RHO_R',RHO_R);
set_param_value('RHO_RF',RHO_RF);
set_param_value('RHO_YF',RHO_YF);
set_param_value('RHO_P',RHO_P);
set_param_value('RHO_Y',RHO_Y);
set_param_value('RHO_E',RHO_E); 

Loop.mod makes me find the optimal value of some parameters, denoted as
RHO_R_opt, RHO_P_opt, RHO_Y_opt, RHO_E_opt
I compare them with the literature, and I confirm they are correct.

Then I face the problem:
I update values of some parameters as follows: (written in the same exercise.m)

set_param_value('RHO_R',RHO_R_opt);  
set_param_value('RHO_P',RHO_P_opt);
set_param_value('RHO_Y',RHO_Y_opt);
set_param_value('RHO_E',RHO_E_opt); 

In the Workspace window, they are truly updated.

BUT, when I continue adding the commands in exercise.m to show IRFs of the updated optimal model, (Loop.mod and optmodel.mod are almost identical, except the former has loops, the latter has updated some parameters)

dynare optmodel.mod noclearall

In the Workspace window, RHO_R, RHO_P, RHO_Y, RHO_E return to OLD values!!

BTW I try to append

for iter = 1:length(M_.params) 
  eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names{iter} ';' ])  
end
params = M_.params;

somewhere in exercise.m, parameters still return OLD values after implementing optmodel.mod.

How to update them correctly?

From what I can see the code is very error-prone. Avoid global variables. In any case, try

verbatim;
params=load('params.mat');
set_param_value('RHO_A',params.RHO_A);
end;

That way, Dynare will not try to replace the defined `parameters` based on the content known to Dynare. Currently, my guess is that your codes is interpreted by the Dynare preprocessor.