  dynare endodeneme.mod  noclearall
  % Remember to add       options_.noprint=1;     
  % just below your call to the solver in your .mod file
  % E.g.
 % stoch_simul(...)
 % options_.noprint=1; 


  % get position of welfare in variable list.
  Welfare_pos=strmatch('Welfare',M_.endo_names,'exact');

  % grid of values.
  RRRss_grid = 0.04:0.01:0.08; 
  % pre-allocate.
  mean.Welfare=zeros(length(RRRss_grid),1);
  mat_loop_MP=zeros(2,length(RRRss_grid));

  n=0; % start counter.
  
  for ii = 1:length(RRRss_grid)
 
     set_param_value('RRRss',RRRss_grid(ii));

         info=stoch_simul(var_list_); % loop over stoch_simul.

         if info ==0
            % Read out mean of welfare.
            mean.Welfare(ii)=oo_.mean(Welfare_pos);
         else 
            fprintf('Here there is an error with this value of RRRss!\n');
            % assign NAN to problematic value.
            mean.Welfare(ii)=NaN;
         end    
   n=n+1;  % Next iteration.
   % Store.
   mat_loop_MP(:,n)=[RRRss_grid(ii);mean.Wel(ii)];
   
  end % loop end.
  
% Plot.
x=mat_loop_MP(1,:);
y=mat_loop_MP(2,:);
plot(x,y)