%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Comments don't work with the preprocessor with macro variables
% Example 1:
% Leave the following lines uncommented and delete Example 2 and the 
% program runs. Comment them (% or //) and Dynare will complain.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@# for macrovariable in -3:3
    @{macrovariable} + @{macrovariable};
@# endfor

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Macro language variable syntax cannot be used in Matlab commands.
% Example 2:
% The following line will break Dynare.  It can be commented or not.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('@{adifferentmacrovariable}');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

var y, c, k, i, l, z, U_c, U_l, m;
varexo e;

parameters bbeta, ppsi, ddelta, aalpha, rrho;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calibrate Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

aalpha   = 0.33;
bbeta    = 0.99;
ddelta   = 0.023;
ppsi     = 1.75;
rrho     = 0.95;  
ssigma   = 0.007 / (1 - aalpha);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Model Equations
%    Period Utility:          U = log(c) + ppsi * log(1 - l)
%    Technology:              y = k^aalpha (exp(z) * l)^(1 - aalpha)
%    Capital LoM:         k(+1) = (1 - ddelta) * k + i
%    Resource Constraint:     y = c + i
%    Shocks:                  z = rrho * z(-1) + e
% Convenience Variables
%    U_c: partial derivative of U with respect to c
%    U_l: partial derivative of U with respect to l
%    m: pricing kernel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

model;
  U_c = 1 / c;
  U_l = -ppsi / (1 - l);
  m = bbeta * U_c / U_c(-1);
  1 = m(+1) * (1 - ddelta + aalpha * k^(aalpha - 1) * (exp(z(+1)) * l(+1))^(1-aalpha));
  -U_l / U_c = (1 - aalpha) * k(-1)^aalpha * exp(z)^(1-aalpha) * l^(-aalpha);
  y = k(-1)^aalpha * (exp(z) * l)^(1 - aalpha);
  i = k - (1 - ddelta) * k(-1);
  y = c + i;
  z = rrho * z(-1) + e;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute Steady State Solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

initval;
  k = 10;
  c = 0.8;
  l = 0.3;
  z = 0;
  U_l = -2.5;
  U_c = 1.25;
  m = 0.99;
end;

shocks;
var e = ssigma^2;
end;

steady;

stoch_simul(nograph, hp_filter = 1600, order = 2);
