Parameter to loop to retrieve standard deviations of endogenous variables

Good afternoon,

Sorry for arising this old post again, but I would like to see how the standard deviations of two variables in my model change in response of different shock magnitudes.
I thought of adding a loop for the standard error of my credit shock (specified in line 129 of the code). I read this post, but I don’t understand how to do it (I do not know how to put your addendum at play)…
I should recover and save two values of oo_.var for every running of the loop.

Could you help me, please?
This is the mod file:
dyn_main.mod (8.1 KB)

Hi asha1,

You could try

% Declare model name.
model_name='yourmodel';
% Call model.
eval(['dynare ',model_name])
% Shock of interest (make shock name as character type)
shock={'eps_credit'};  exo_name=char(shock);
% Find position in declaration of exogenous variables.
eps_pos=strmatch(exo_name,M_.exo_names,'exact');
% get variable positions in variable list.
pi_pos=strmatch('pi',M_.endo_names,'exact');
y_pos=strmatch('y',M_.endo_names,'exact');
% Grid.
SIGM_grid = 0.1:0.025:0.5; % Size of shock.
% Pre-allocate.
variance.pi=zeros(length(SIGM_grid),1);
variance.y=zeros(length(SIGM_grid),1);
% Storage matrix.
mat_loop=zeros(3,length(SIGM_grid));
% Start counter.
n=0;
% Start loop.
  for ii = 1:length(SIGM_grid)
          % Assign variance to the correct diagonal element in the
          % variance-covariance matrix.
          M_.Sigma_e(eps_pos,eps_pos) = SIGM_grid(ii); 
          
          info=stoch_simul(var_list_); % loop over stoch_simul.
 
      if info == 0
        %read out variances.    
        variance.pi(ii)=oo_.var(pi_pos,pi_pos);
        variance.y(ii)=oo_.var(y_pos,y_pos);
      else
        variance.pi(ii)=NaN;
        variance.y(ii)=NaN;
     end
% Next iteration.   
n=n+1;
% Store.
mat_loop(:,n)=[SIGM_grid(ii);sqrt(variance.pi(ii));sqrt(variance.y(ii))];
  end
 % End

When you invoke the solver, I suggest you set irf=0 and specify

options_.nomoments=0;
options_.nofunctions=1;
options_.nograph=1;
options_.verbosity=0;
options_.noprint=1;
options_.TeX=0;

:slight_smile:

Dear Cmarch,
Thank you so much for your help.
I’m trying to apply it… So far, I get an error when I use the code you wrote: “shockloop.mod: line 52, col 3 - line 53, col 0: syntax error, unexpected $end”
I don’t see any missing “end”.

Please provide the mod-file

shock_loop.mod (1.7 KB)

Sorry, I did not receive a notification of your message and did not recheck until today…
Here you have the mod-file (based on cmarch help) and all the files of my code. The running file is “dyn_table.m” and “dyn_main.mod” is the main file with the model.

Thank you so much!

dyn_main.mod (8.3 KB) dyn_extract.m (1.3 KB) dyn_main_steadystate.m (955 Bytes) dyn_stats.m (2.1 KB) dyn_table.m (3.8 KB) findss.m (503 Bytes) stst.m (1.9 KB)

@asha1 But what is the problem? Your codes runs on my machine without error.

I wanted to get a grid of values for my shock variance, but I do not manage to make shock_loop.mod run. I get the error “syntax error, unexpected $end”.

Thanks.

Then please provide the file that creates this problem.

Dear Johannes,

I did upload it in my previous message… it is called shock_loop.mod. If you run it, it gives the error I mentioned.

Thank you so much.

Your mod-file is not a proper mod-file. It contains only Matlab-code, but then does not use Matlab-conform comments.