Loop over parameters

Good morning Prof. Pfeifer,

That is correct. I correct the code chunk. :slightly_smiling_face:

stoch_simul(order=2,periods=0,irf=0);
%make sure Dynare does not print out unnecessary output during runs
options_.nomoments=0;
options_.nofunctions=1;
options_.nograph=1;
options_.verbosity=0;
options_.noprint=1; % set noprint option to suppress error 
%messages within loop (If you have this option in your 
%code you need not use the try-catch statement below)
options_.TeX=0;
    % Read out variable position 
    pi_pos=strmatch('pi',M_.endo_names,'exact');

    theta_grid = [0:0.1:1];
        chi_grid = [0:0.1:1];
        for ii = 1:length(theta_grid)
           for jj = 1:length(chi_grid)
        set_param_value('theta',theta_grid(ii))
        set_param_value('chi',chi_grid(jj))
    % Set seed
    set_dynare_seed('default');  % (If you have this option in your code you 
% need not use the options_.noprint=1 statement above)
    try 
    info=stoch_simul(M_.endo_names); % loop over stoch_simul
    catch 
        warning('Unfortunately, there seems to be a problem with this combination of parameters. Assigning a value of NaN to info.');
        info = NaN; 
    end  
        if info ==0
            %read out variance of inflation   
            variance.pi(ii,jj)=oo_.var(pi_pos,pi_pos);
        else 
            fprintf('Here there is an error with this combination of paramters!\n');
         variance.pi(ii,jj)=NaN;
       end
    end
end
1 Like