IRF for multiple parameter values

Hi

I am currently simulating a model on Dynare using the following code below:

WealthShare4.mod (1.7 KB)

The code generates IRFs for my given calibration. However I would like the IRFs to display how the response variable changes as I vary a given parameter (PSI in the code). I tried the following:

rhos = 0.5:1.5;
first_time = 1;
for i=1:length(rhos)
if first_time
set_param_value(‘PSI’,rhos(i));
dynare WealthShare4.mod;
first_time = 0;
else
set_param_value(‘PSI’,rhos(i));
info = stoch_simul(var_list_);
if info;
disp('Computation fails for PSI = ’ num2str(PSI)]);
end;
end
end

However this does not work and I get a syntax error problem. Any thoughts?

It should be something along the lines of

dynare WealthShare4.mod;
rhos = 0.5:1.5;
first_time = 1;
for i=1:length(rhos)
    set_param_value('PSI',rhos(i));
    [info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);
    if info;
        disp(['Computation fails for PSI = ' num2str(PSI)]);
    end
end
1 Like

It looks like the code just ran the model separately for the two values of PSI. How could I generate a single IRF graph for a given variable that plots the impulse response for different levels of IES? Is this possible on Dynare? My first attempt was something like this:

dynare WealthShare4.mod;
load('WealthShare4_results.mat', 'oo_')
irf1=oo_.irfs;
save irf1

load irf1
dynare WealthShare3.mod noclearall
load('WealthShare3_results.mat', 'oo_')
irf2=oo_.irfs;
save irf2

load irf2
ending_cell={'g'};
for ii=1:length(ending_cell)

HOR=1:1:20;

var={'dws','e'};

figure for jj=1:length(var)
subplot(1,2,jj)
eval('irf1.' var{1,jj},ending_cell{1,ii}]);
eval('irf2.' var{1,jj},ending_cell{1,ii}]);

load irf2

end

But it doesn’t seem to work.

dynare WealthShare4.mod;

rhos=[0.5 0.6];
for ii=1:length(rho)
    set_param_value('PSI',rhos(ii));
    [info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);
    if ~info
        irf_cell{ii}=oo_.irfs;
    end
end

shock_ending_cell={'g'};
var_names={'dws','e'};
for shock_iter=1:length(shock_ending_cell)  
    figure('Name',shock_ending_cell{shock_iter})
    for var_iter=1:length(var_names)
        subplot(1,2,var_iter)       
        plot(1:options_.irf,irf_cell{1}.([var_names{var_iter},'_',shock_ending_cell{shock_iter}]))
        hold on
        plot(1:options_.irf,irf_cell{2}.([var_names{var_iter},'_',shock_ending_cell{shock_iter}]))
        title(var_names{var_iter})
    end    
end

should work together with

var ch cf cdiff ddiff df dh vh vf rh rf wh wf mh mf e ws dws rdiff;
varexo h f g;

parameters DELTA THETA PSI TAU_H TAU_F MU RHO;

DELTA=0.98;
PSI=0.01;
TAU_H=0.5;
TAU_F=1.5;
THETA=(1-2)/(1-1/0.01); 
MU=0.0015;
RHO=.9;

model;
vh       = DELTA^THETA * exp((-THETA/PSI)*dh(+1) + (THETA-1)*log((1+vh(+1))*exp(dh(+1))/vh) ) * (1+vh(+1))*exp(dh(+1));
vf       = DELTA^THETA * exp((-THETA/PSI)*df(+1) + (THETA-1)*log((1+vf(+1))*exp(df(+1))/vf) ) * (1+vf(+1))*exp(df(+1));
ch        = RHO * ch(-1) - h - TAU_H * g;
cf        = RHO * cf(-1) - f - TAU_F * g;
cdiff     = ch - cf;
wh       = vh * exp(ch);
wf       = vf * exp(cf);
ws       = log(wh) - log(wf);
dws       = ws - ws(-1);
dh        = ch - ch(-1);
df        = cf - cf(-1);
ddiff     = dh - df;
rh       = ((1+vh)*exp(dh))/vh(-1);
rf       = ((1+vf)*exp(df))/vf(-1);
rdiff    = rh - rf;
mh        = DELTA^THETA * exp((-THETA/PSI)*dh + (THETA-1)*log(rh));
mf       = DELTA^THETA * exp((-THETA/PSI)*df + (THETA-1)*log(rf));
e        = mf - mh;
end;

initval;
ch=0;
cf=0;
dh=0;
df=0;
dws=0; 

vh=100;
vf=100;
cdiff    = ch - cf;
ddiff    = dh - df;
rh       = ((1+vh)/vh)*exp(dh);
rf       = ((1+vf)/vf)*exp(df);
wh       = vh * exp(ch);
wf       = vf * exp(cf);
mh        = DELTA^THETA * exp((-THETA/PSI)*dh + (THETA-1)*log(rh));
mf        = DELTA^THETA * exp((-THETA/PSI)*df + (THETA-1)*log(rf));
e         = mf - mh;
ws        = log(wh) - log(wf);
rdiff        = rh - rf;
end;

shocks;
var h;
stderr 0.01;
var f;
stderr 0.01;
var g;
stderr 0.01;
end;

resid;
steady;
check;

stoch_simul(order=3, periods=0,simul_replic=100, irf=20) dws e;```

Thanks for the help, this code seems to work. However I had one last question. I would like to change the sub plot titles which currently appear as variable names. I tried the following:

dynare WealthShare4.mod;

rhos=[0.5 1.5 2.5];
for ii=1:length(rhos)
    set_param_value('PSI',rhos(ii));
    [info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);
    if ~info
        irf_cell{ii}=oo_.irfs;
    end
end

shock_ending_cell={'g'};
var_names={'dws','rdiff','e'};
for shock_iter=1:length(shock_ending_cell)  
    figure('Name',shock_ending_cell{shock_iter})
    for var_iter=1:length(var_names)
        subplot(2,2,var_iter)       
        plot(1:options_.irf,irf_cell{1}.([var_names{var_iter},'_',shock_ending_cell{shock_iter}]))
        legend({'$\psi=0.5$','$\psi=1.5$','$\psi=2.5$'},'Interpreter','latex')
title('$\tilde{W}_{t}$', 'Interpreter','latex', 'fontweight', 'bold', 'Units', 'normalized', 'Position', [0.5, 1.05, 0]);
        hold on
        plot(1:options_.irf,irf_cell{2}.([var_names{var_iter},'_',shock_ending_cell{shock_iter}]))
        legend({'$\psi=0.5$','$\psi=1.5$','$\psi=2.5$'},'Interpreter','latex')
  title('$\mathcal{E}_{t}$', 'Interpreter','latex', 'fontweight', 'bold', 'Units', 'normalized', 'Position', [0.5, 1.05, 0]);
    end    
end

When I do this, it just changes the titles of both subplots to the last title in the code. Do you have any idea on how I can change the subplot titles in this loop to reflect the two corresponding titles I’ve written in latex code?

I would guess you are looking for

shock_ending_cell={'g'};
var_names={'dws','rdiff','e'};
var_title={'$\tilde{W}_{t}$','$R$','$\mathcal{E}_{t}$'};
for shock_iter=1:length(shock_ending_cell)  
    figure('Name',shock_ending_cell{shock_iter})
    for var_iter=1:length(var_names)
        subplot(2,2,var_iter)       
        for par_iter=1:size(irf_cell,2)
            hold on
            plot(1:options_.irf,irf_cell{par_iter}.([var_names{var_iter},'_',shock_ending_cell{shock_iter}]))
        end
        legend({'$\psi=0.5$','$\psi=1.5$','$\psi=2.5$'},'Interpreter','latex')
        title(var_title{var_iter}, 'Interpreter','latex', 'fontweight', 'bold', 'Units', 'normalized', 'Position', [0.5, 1.05, 0]);
    end    
end