% Dynare Code for solving a one-sector RBC model with IRS and uncertainty shock



% Qazi Haque
% The University of Adelaide
% November 1 2014


%----------------------------------------------------------------
% 1. Defining variables
%----------------------------------------------------------------

var z sigma_z K H C X w r Y;
varexo e e_sigma;

%----------------------------------------------------------------
% 2. Defining parameters
%----------------------------------------------------------------

parameters v chi gamma beta delta alpha rho_z mean_sigma_z rho_sigma_z sigma_sigma_z;

%----------------------------------------------------------------
% 3. Calibration
%----------------------------------------------------------------

% Structural parameters

v = 2.5805;
chi = 1;
gamma = 0;
beta = 0.99;
delta = 0.025;
alpha = 0.36;

% Shock parameters

rho_z = 0.9;
mean_sigma_z = 0.01;
rho_sigma_z = 0.83;
sigma_sigma_z = 0.37;

%----------------------------------------------------------------
% 4. Model
%----------------------------------------------------------------

model;

% Household's intra-temporal leisure consumption trade-off

v*(H^gamma)*(C^chi) = w;

% Household's Euler equation

1 = beta*(C(+1)^(-chi)/C^(-chi))*(r(+1) + (1-delta));

% The two budget constraints from the household's problem

C + X = Y;

K = X + (1-delta)*K(-1);

w = (1-alpha)*(Y/H);

r = (alpha)*(Y/K(-1));

Y = ((z)*(K(-1)^alpha)*(H^(1-alpha)));

% Stochastic process for technology shock

log(z) = rho_z*log(z(-1)) + sigma_z*e;

% 19. Stochastic process for second moment shock

log(sigma_z) = (1-rho_sigma_z)*log(mean_sigma_z) + rho_sigma_z*log(sigma_z(-1)) + sigma_sigma_z*e_sigma;


end;


initval;

z = 1;
sigma_z = mean_sigma_z;
K = 12.6698;
H = 0.3335;
C = 0.9186;
X = 0.1268;
w = 2.3706;
r = 0.0351;
Y = 1.2353;
e = 0;
e_sigma = 0;

end;


shocks;
var e = 1;
var e_sigma = 1;
end;

steady;
check;

options_.pruning=1;
stoch_simul(order = 3, periods = 2096, drop = 2000);


ergo_mean = mean(oo_.endo_simul,2);

ex_ = zeros(20,2);

out = simult_(ergo_mean,oo_.dr,ex_,3);

ex_(1,2) = 1;
output = simult_(ergo_mean,oo_.dr,ex_,3);


Capital = ((output(3,:)- out(3,:))./ergo_mean(3))*100;

Labor = ((output(4,:)- out(4,:))./ergo_mean(4))*100;

Consumption = ((output(5,:)- out(5,:))./ergo_mean(5))*100;

Investment = ((output(6,:)- out(6,:))./ergo_mean(6))*100;

wage = ((output(7,:)- out(7,:))./ergo_mean(7))*100;

rental = ((output(8,:)- out(8,:))./ergo_mean(8))*100;

GDP = ((output(9,:)- out(9,:))./ergo_mean(9))*100;

Technologyshock = (output(1,:)- out(1,:));

Uncertaintyshock = (output(2,:)- out(2,:));


close all;


figure;
verbatim;

subplot(4,2,1)
plot(Capital);
legend('Capital')


subplot(4,2,2)
plot(Labor);
legend('Labor')


subplot(4,2,3)
plot(Consumption);
legend('Consumption')

subplot(4,2,4)
plot(Investment);
legend('Investment')

subplot(4,2,5)
plot(wage);
legend('real wage')

subplot(4,2,6)
plot(rental);
legend('real rental')

subplot(4,2,7)
plot(GDP);
legend('Output')


end;

