How can I let Dynare randomly generate a set of shocks

Hi everyone,

I have some problems for one of my assignments. First, I need to let you know that I’m a beginner with dynare. That’s actually the 2nd time I’m using it and it’s for an assignment.

Our professor asked us to calibrate a usual RBC model (I did it with R). Then she ask us to simulate the model in 2 differents ways :

  • Given your estimated distribution of errors, let Dynare randomly generate a set of shocks for you.
    -Feed in your own estimated residuals into Dynare and simulate.

I tried to do it. But I’m not convince about my code. Can someone let me know if I did it right ?

RBCModel_Part1 correspond to this question :Given your estimated distribution of errors, let Dynare randomly generate a set of shocks for you ! And RBCModel_Part2 correspond to Feed in your own estimated residuals into Dynare and simulate.

Thanks a lot,
Marie
RBCModel_Part1.mod (1.6 KB)
RBCModel_Part2.mod (1.5 KB)

As you did not provide the Excel-file, I cannot run the second file. The more elegant Dynare version would be:

var c k y w r n i z ;
varexo e;
parameters alpha eta beta delta rho sigma;

alpha=0.4001267;
eta=1.5949;
beta=0.9646157;
delta = 0.04517506;
rho = 0.7052543;
sigma=0.6119084;
sigmae=0.05441425;

model;
(1/(c^(sigma))) = beta*(1/(c(+1))^(sigma))*(1+r(+1)-delta);
w = (c^(sigma))*(n^(eta));
c+ i= y;
y = (exp(z))*(k(-1)^alpha)*(n)^(1-alpha);
w = (exp(z))*(1-alpha)*(k(-1)^alpha)*(n)^(-alpha);
r = (exp(z))*(alpha)*(k(-1)^(alpha-1))*((n)^(1-alpha));
i = k-(1-delta)*k(-1);
z = rho*z(-1)+e;
end;

//BLOCK 3: Specify the initial steady state and end steady state
steady_state_model;
r = (1/beta)-1+delta;
w=(1-alpha)*(r /alpha)^(alpha/(alpha-1));
n = (((r/alpha)^(alpha/(alpha-1))- delta*(r/alpha)^(1/(alpha-1)))/((1-alpha)*(r/alpha)^(alpha/(alpha-1)))^(1/sigma))^(-sigma/(eta+sigma));
y = ((r/alpha)^(alpha/(alpha-1)))*n;
i = (delta*(r/alpha)^(1/(alpha-1)))*n;
c=y-i;
k = (alpha*y)/r;
z = 0;
end;

shocks;
var e;
stderr 0.05441425;
end;
resid;
steady;

stoch_simul(order=2,irf=140,periods=200);
options_.rplottype=2;
rplot y c r k z ;

Note that I fixed both your steady state computations and the model FOC for the interest rate (wrong exponent on n)

Hi Johannes Pfeifer,

Thank you for your help and your response.
Residual.xls (29.5 KB)
I thought that for part 1, it was necessary to produce different shocks. But it seems not.

I attach my Excel file for the 2nd part.

A compact version would be

var c k y w r n i z ;
varexo e;
parameters alpha eta beta delta rho sigma;

alpha=0.4001267;
eta=1.5949;
beta=0.9646157;
delta = 0.04517506;
rho = 0.7052543;
sigma=0.6119084;
sigmae=0.05441425;

model;
(1/(c^(sigma))) = beta*(1/(c(+1))^(sigma))*(1+r(+1)-delta);
w = (c^(sigma))*(n^(eta));
c+ i= y;
y = (exp(z))*(k(-1)^alpha)*(n)^(1-alpha);
w = (exp(z))*(1-alpha)*(k(-1)^alpha)*(n)^(-alpha);
r = (exp(z))*(alpha)*(k(-1)^(alpha-1))*((n)^(1-alpha));
i = k-(1-delta)*k(-1);
z = rho*z(-1)+e;
end;

//BLOCK 3: Specify the initial steady state and end steady state
steady_state_model;
r = (1/beta)-1+delta;
w=(1-alpha)*(r /alpha)^(alpha/(alpha-1));
n = (((r/alpha)^(alpha/(alpha-1))- delta*(r/alpha)^(1/(alpha-1)))/((1-alpha)*(r/alpha)^(alpha/(alpha-1)))^(1/sigma))^(-sigma/(eta+sigma));
y = ((r/alpha)^(alpha/(alpha-1)))*n;
i = (delta*(r/alpha)^(1/(alpha-1)))*n;
c=y-i;
k = (alpha*y)/r;
z = 0;
end;


shocks;
var e;
stderr 0.05441425;
end;
steady;

stoch_simul(order=2,irf=0,periods=0);
%Feeding my residuals 

shock_matrix =readmatrix('Residual.xls'); 

initial_condition_states = repmat(oo_.dr.ys,1,M_.maximum_lag);

y2 = simult_(M_,options_,initial_condition_states,oo_.dr,shock_matrix,options_.order);
y_IRF = y2(:,M_.maximum_lag+1:end)-repmat(oo_.dr.ys,1,size(shock_matrix,1));


figure
for ii=1:M_.orig_endo_nbr
    subplot(3,3,ii)
    if max(abs(y_IRF(ii,:)))>1e-12 %get rid of numerical inaccuracies
        plot(y_IRF(ii,:));
    else
        plot(zeros(y_IRF,1));
    end
    title(deblank(M_.endo_names(ii,:)));
end

Why does your residual data show such weird fluctuations?