Parameter loop in Dynare 5.x

Hi everyone,

Quick question, I am using the following adjusted code from above:

OMEGARS = 1:1:5; %specifies the different values I want to loop over
first_time = 1;

for i = 1:length(OMEGARS)
    if first_time           
        dynare mymodfile noclearall;
        first_time = 0;
    else                 
        set_param_value('OMEGAR',OMEGARS(i));        
        info = stoch_simul(M_, options_, oo_, var_list_);
        %results_cell{i} = oo_ ;
        plot(oo_.irfs.variable_eps_j);
        hold on;
        %disp('I am plotting');       
    end 
        if info
          disp(['Computation fails for OMEGAR = ' num2str(OMEGARS)]);
        end
        
 end

Inside the mod file I call the ‘load parameter_file’ where all parameters are set, including the parameter of interest OMEGAR. The mod file also contains the steady state which was derived by hand. As OMEGAR changes, the steady state changes but this doesn’t seem to be a problem when we loop over stoch_simul.

So, here is the problem. When I loop over dynare (which we shouldn’t do), I get different irfs for the different OMEGARs. However, when I use the code in the m.file above, it seems the irfs get overwritten as I end up with five times the same values. Has anyone got an idea what I am doing wrong? Thanks for your help!

Rob

1 Like

Without the files it is impossible to tell.

For Dynare 5, you forgot to output the results from stoch_simul:


clear all;

OMEGARS = 1:1:5;
first_time = 1;

for i = 1:length(OMEGARS)
    if first_time           
        dynare rentalhousing noclearall;
        first_time = 0;
    else                 
        set_param_value('OMEGAR',OMEGARS(i));        
        [info, oo_] = stoch_simul(M_, options_, oo_, var_list_);
        if info
          disp(['Computation fails for rho = ' num2str(OMEGARS)]);
        else
        %results_cell{i} = oo_ ;
        plot(oo_.irfs.data_QQ_eps_j);
        hold on;
        disp('I am plotting');
        oo_.irfs.data_QQ_eps_j
        end
    end 
        
 end

3 Likes

Thanks Johannes!

Sorry to reopen this thread, but I have a very similar problem which I believe is the result of a stupid mistake I am making, but that I cannot manage to solve it.

I am trying to loop multiple parameters in my model to conduct sensitivity analysis. As in the case above, changes in the parameters will affect the steady state. I am stuck with the no steady state error:

Error using [print_info](matlab:matlab.lang.internal.introspective.errorDocCallback(‘print_info’, ‘/Applications/Dynare/6.2-arm64/matlab/print_info.m’, 33)) ([line 33](matlab: opentoline(‘/Applications/Dynare/6.2-arm64/matlab/print_info.m’,33,0)))
The steadystate file did not compute the steady state

Error in [stoch_simul](matlab:matlab.lang.internal.introspective.errorDocCallback(‘stoch_simul’, ‘/Applications/Dynare/6.2-arm64/matlab/stochastic_solver/stoch_simul.m’, 119)) ([line 119](matlab: opentoline(‘/Applications/Dynare/6.2-arm64/matlab/stochastic_solver/stoch_simul.m’,119,0)))
print_info(info, options_.noprint, options_);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [temp](matlab:matlab.lang.internal.introspective.errorDocCallback(‘temp’, ‘/Users/ettoreg/Documents/GitHub/Pereira Serra - Gallo 2025/dynare/temp.m’, 9)) ([line 9](matlab: opentoline(‘/Users/ettoreg/Documents/GitHub/Pereira Serra - Gallo 2025/dynare/temp.m’,9,0)))
[info, oo_] = stoch_simul(M_, options_, oo_, var_list_);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I am sure the model reaches the steady state with all values of taur in the sequence, but it seems that the steady state does not update when taur changes.

temp.m (564 Bytes)

temp.mod (8.7 KB)

I am attaching both the Matlab function and the .mod file (in which the problem most likely lies). Could you please clarify what I am getting wrong and how to solve this?

Thank you in advance for your help @jpfeifer !

Best,

Ettore

It seems you are having a whole bunch of objects that depend on taur that are set only once before the model block. Definitions like

sp = xi * (Inbar + Iebar) / ((1 - taur) * (Ynbar - wpbar * Lbar - (1 - xi) * (Inbar + Iebar)));

belong in the steady_state_model block.

temp.mod (8.7 KB)
temp.m (564 Bytes)