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)
% 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
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”.
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.
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”.