% Example of simulation then estimation of a model
% Michel Juillard, July 31, 2006
% this file estimates the data. See rbc_investment0.mod for simulation
%
% using
%
% RBC Model with investment specific technological change. 
%
% Jesus Fernandez-Villaverde
% Philadelphia, March 4, 2005

%----------------------------------------------------------------
% 0. Housekeeping
%----------------------------------------------------------------

close all;

%----------------------------------------------------------------
% 1. Defining variables
%----------------------------------------------------------------

var y c k i l y_l z1 z2;
varexo e1 e2;

parameters beta psi delta alpha rho1 rho2 sigma1 sigma2;

%----------------------------------------------------------------
% 2. Model
%----------------------------------------------------------------

model; 
  (1/c) = beta*(1/c(+1))*(alpha*(k^(alpha-1))*(exp(z1(+1))*l(+1))^(1-alpha)+(1-delta)*exp(z2-z2(+1)));
  psi*c/(1-l) = (1-alpha)*(k(-1)^alpha)*(exp(z1)^(1-alpha))*(l^(-alpha));
  c+i = y;
  y = (k(-1)^alpha)*(exp(z1)*l)^(1-alpha);
  k = (1-delta)*k(-1)+exp(z2)*i;
  y_l = y/l;
  z1 = rho1*z1(-1)+e1;
  z2 = rho2*z2(-1)+e2;
end;

%----------------------------------------------------------------
% 3. Steadystate guess values 
%    (an explicit ..._steadystate.m function would be much faster)
%----------------------------------------------------------------

initval;
  k  = 9;
  c  = 0.76;
  l  = 0.3;
  z1 = 0; 
  z2 = 0;
end;

%----------------------------------------------------------------
% 4. Parameter priors
%----------------------------------------------------------------

estimated_params;
alpha, uniform_pdf,0.33,0.15;
beta, uniform_pdf,,,0.95,1.0;
delta, uniform_pdf,0.023,0.005;
psi, uniform_pdf, 1.75,0.2;
rho1, uniform_pdf,,,0.8,1; 
rho2, uniform_pdf,,,0.5,0.8; 
stderr e1, uniform_pdf,0.01,0.005;
stderr e2, uniform_pdf,0.007,0.003;
end;

%----------------------------------------------------------------
% 5. Observed variables (consumption and labor)
%----------------------------------------------------------------
varobs c l;

%----------------------------------------------------------------
% 6. Estimation
%     - uses simulated data
%     - drop 100 observations as 'warm up'
%     - uses 200 quarters of artificial data
%     - searches only for posterior mode
%----------------------------------------------------------------
estimation(datafile=rbc_investment_data,first_obs=100,nobs=200,mh_replic=0);
