# Loop over parameters

**URL:** <https://forum.dynare.org/t/loop-over-parameters/3335>\
**Category:** Stochastic simulations\
**Created:** [14 August 2013 11:44 UTC](https://forum.dynare.org/t/loop-over-parameters/3335 "2013-08-14T11:44:16Z")\
**Posts on this page:** 1\
**Showing post:** 67

<div class="post-metadata">

**Author:** ![cmarch](https://forum.dynare.org/user_avatar/forum.dynare.org/cmarch/32/7827_2.png) [@cmarch](https://forum.dynare.org/u/cmarch)\
**Post date:** [9 May 2019 07:50 UTC](https://forum.dynare.org/t/loop-over-parameters/3335/67 "2019-05-09T07:50:28Z")

</div>

Good morning Prof. Pfeifer,

That is correct. I correct the code chunk. 🙂

```auto
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

```

---

_[View the full topic](https://forum.dynare.org/t/loop-over-parameters/3335)._
