
// ///////////////////////////////// //
/* TESIS MAESTRIA EN ECONOMETRIA */
// ///////////////////////////////// //

// ////////////////////////////// //
/* UNIVERSIDAD TORCUATO DI TELLA */
// ////////////////////////////// //

// /////////////////////// //
/* LAUTARO GONZALEZ 11Z607 */
// /////////////////////// //

// ///////////////////////////////// //
/* MODELO DSGE CALIBRADO */
// ///////////////////////////////// //

// ///////////////////////////////// //
/* REFERENCIAS */
/* Adolfson, M., S. Laseen, J. Linde, and M. Villani. 2007. "Bayesian Estimation of an Open Economy DSGE Model with Incomplete Pass-Through." */
/* Journal of International Economics 72(2), pp. 481-511. */
// ///////////////////////////////// //

// ///////////////////////////////// //
/*  EJECUCION EN DYNARE  */
// ///////////////////////////////// //

// ///////////////////////////////// //
/* DECLARACION DE VARIABLES ENDOGENAS Y EXOGENAS */ 
// ///////////////////////////////// //

var 

/* VARIABLES ENDOGENAS */

pi_hat pi_mc pi_mi pi_x w_barhat c_hat i_hat psi_zhat P_k dS H_hat k_barhat k_hat 
q_hat m_barhat mu_hat a gamma_mcdhat gamma_midhat gamma_xstar mc_x R_hat E 

/* VARIABLES RESTO DEL MUNDO */

 pistar_hat ystar_hat Rstar_hat 

/* VARIABLES GOBIERNO */

 tauk_hat tauy_hat tauc_hat tauw_hat g_hat 

/* PROCESOS EXOGENOS */

  epsilon mu_zhat zeta_c zeta_h lambda_dhat lambda_mchat lambda_mihat phi_tilde Upsilon z_tildestar lambda_x pi_bar 

/* VARIABLES ENDOGENAS ADICIONALES */

mc rk_hat mc_mc mc_mi pi_c y_hat x R_fhat u gamma_fhat gamma_cdhat gamma_idhat;

varexo 

/* VARIABLES EXOGENAS */

epsilon_tauk epsilon_tauw epsilon_tauc epsilon_tauy epsilon_lambdad epsilon_lambdamc 
epsilon_lambdami epsilon_lambdax epsilon_muz epsilon_epsilon
epsilon_Upsilon epsilon_zetac epsilon_phitilde 
epsilon_R epsilon_pibar epsilon_pistar epsilon_ystar epsilon_Rstar epsilon_rhog
epsilon_m epsilon_ztildestar;

// ///////////////////////////////// //
/* IDENTIFICACION DE LOS PARAMETROS DEL MODELO */
// ///////////////////////////////// //

parameters 

beta alpha eta_c sigma_a mu sigma_L delta lambda_w omega_i omega_c tau_y 
tau_c rho_pibar gr A_q A_L rho_tauk rho_tauw sigma_q 

xi_d xi_mc xi_mi xi_x xi_w xi_e kappa_w kappa_d kappa_mc kappa_mi kappa_x lambda_d 
lambda_mi lambda_mc S_tilde b eta_i eta_f mu_z tau_w tau_k phi_a
rho_muz rho_epsilon rho_Upsilon rho_zetac rho_phitilde
rho_lambdamc rho_lambdami rho_lambdax rho_R  rho_pi rho_y rho_x rho_dpi rho_dy rho_m rho_ztildestar

/* RELACIONES DE ESTADO ESTACIONARIO */

b_w eta_0 eta_1 eta_2 eta_3 eta_4 eta_5 eta_6 eta_7 eta_8 eta_9 eta_10 pi R R_f eta_mc eta_mi gamma_id gamma_cd gamma_dc gamma_mcc gamma_cmc gamma_imi gamma_mii
r_k w_bar k_H D1 D2 D3 D4 H c psi_z y_bar g q m_bar k k_bar i c_m i_m y_star 

/* VAR GOBIERNO Y RESTO DEL MUNDO */

ForLag111 ForLag112 ForLag113 ForLag121 ForLag122 ForLag123 ForLag131 ForLag132 ForLag133 
ForLag211 ForLag212 ForLag213 ForLag221 ForLag222 ForLag223 ForLag231 ForLag232 ForLag233 
ForLag311 ForLag312 ForLag313 ForLag321 ForLag322 ForLag323 ForLag331 ForLag332 ForLag333 
ForLag411 ForLag412 ForLag413 ForLag421 ForLag422 ForLag423 ForLag431 ForLag432 ForLag433  
FisLag111 FisLag112 FisLag113 FisLag121 FisLag122 FisLag123 FisLag131 FisLag132 FisLag133 
FisLag211 FisLag212 FisLag213 FisLag221 FisLag222 FisLag223 FisLag231 FisLag232 FisLag233;

// ///////////////////////////////// //
/* DECLARACION DE LOS VALORES DE LOS PARAMETROS */
// ///////////////////////////////// //

/* FOREIGN VAR */

/* pstar_hat */

ForLag111 = 0.723;
ForLag112 = 0.323;
ForLag113 =-0.013;
ForLag211= -0.402;
ForLag212= -0.389;
ForLag213=  0.014;
ForLag311= -0.028;
ForLag312=  0.056; 
ForLag313=  0.004;
ForLag411= -0.096;
ForLag412=  0.310;
ForLag413= -0.006;

/* ystar_hat */

ForLag121=  -0.111;
ForLag122=   0.827;
ForLag123=   0;
ForLag221=  -0.262;
ForLag222=  -0.040;
ForLag223=   0.006;
ForLag321=  -0.008;
ForLag322=  -0.073;
ForLag323=  -0.002;
ForLag421=  -0.099;
ForLag422=   0.112;
ForLag423=  -0.001;

/* rstar_hat */

ForLag131 = -6.137;
ForLag132 = 10.825;
ForLag133 = 1.372;
ForLag231=  1.801;
ForLag232=  -10.555;
ForLag233=  -0.258;
ForLag331=  3.627;
ForLag332=  4.470;
ForLag333=  -0.374;
ForLag431=  -0.942;
ForLag432=  1.749;
ForLag433=  0.058;

/* FISCAL VAR */

FisLag111=  0.182;
FisLag112=  0.435;
FisLag113= -0.006;
FisLag121= -0.262;
FisLag122=  0.519;
FisLag123=  0.014;
FisLag131= -2.972;
FisLag132=  2.570;
FisLag133=  0.920;
FisLag211=  0.133;
FisLag212= -0.161;
FisLag213= -0.006;
FisLag221=  0.139;
FisLag222=  0.274;
FisLag223= -0.015;
FisLag231= -0.658;
FisLag232= -0.808;
FisLag233= -0.400;


mu=1.04; /* money growth rate */ /* CUENTAS NACIONALES */
beta=0.989; /* Discount factor */ /* SAMBA */
delta=0.015; /* depreciation rate */ /* SAMBA */
alpha=0.1869; /* Capital share in production */ /* CUENTAS NACIONALES */
A_L=7.5;/* constant in labour disutility function */
sigma_L=1.00; /* labor supply elasticity */ /* SAMBA */
lambda_w=1.05; /* wage markup */
omega_i=0.1916; /* imported investment share */ /* CUENTAS NACIONALES */
omega_c=0.0638; /* imported consumption share */ /* CUENTAS NACIONALES */
rho_pibar=0.84;/* inflation target persistence */ /* SAMBA */
gr=0.19; /* G/Y ratio */ /* CUENTAS NACIONALES */
tau_y=0.11; /* labor income tax */
tau_c=0.08; /* value added tax */ /* TASA PROMEDIO */
A_q=0.70; /* CUENTAS NACIONALES */
rho_tauk=0.53; /* AR */
rho_tauw=0.94; /* AR */
sigma_q=10.62; /* VARIANZA DE DINERO */
eta_c=6.00;  /* substitution elasticity */ /* CALIBRADO CARVALHO Y VALLI */
sigma_a=1000000; /* capital utilization cost */
xi_w=0.75; /* CALVO RIGIDEZ EN SALARIOS */ /*SAMBA*/
xi_d=0.74; /* CALVO RIGIDEZ EN PRECIO BIENES DOMESTICOS */ /* SAMBA */ 
xi_mc=0.64; /* CALVO RIGIDEZ EN PRECIO BIENES DE IMPORTACION */ /* SAMBA */
xi_mi=0.65; /* CALVO RIGIDEZ EN PRECIO BIENES DE IMPORTACION DE INVERSION */ /* SAMBA */
xi_x=0.77; /* CALVO RIGIDEZ EN PRECIO DE EXPORTACIONES *//* SAMBA */
xi_e=0.787; /* CALVO RIGIDEZ EN CONTRATACION */
kappa_w =0.49; /* INDEXACION SALAROPS */ /* SAMBA */
kappa_d=0.33;  /* INDEXACION PRECIOS DOMESTICOS */ /* SAMBA */
kappa_mc=0.65; /* INDEXACION IMPORTACION BIENES DE CONSUMO */ /* SAMBA */
kappa_mi=0.55; /* INDEXACION IMPORTACION BIENES DE INVERSION */ /* SAMBA */
kappa_x=0.35; /* INDEXACION EXPORTACIONES */ /* SAMBA */
lambda_d=1.222; /* MARK UP BIENES DOMESTICOS */
lambda_mc=1.633; /* MARK UP PRECIO BIENES DE IMPORTACION DE CONSUMO */
lambda_mi=1.275; /* MARK UP PRECIO BIENES DE IMPORTACION DE INVERSION*/
S_tilde=3.42; /* investment adjustment cost */ /* SAMBA */
b=0.74; /* habit formation */ /*SAMBA*/
eta_i=1.696; /* substitution elasticity investment */
eta_f=1.486; /* substitution elasticity foreign */
mu_z=1.009; /* technology growth */ /* SAMBA */
tau_k=0.06; /* capital income tax */ /* CUENTAS NACIONALES */
tau_w=0.03; /* Labour pay-roll tax */ /* CUENTAS NACIONALES */
phi_a=0.252; /* SAMBA */ /* PRIMA DE RIESGO */
rho_muz=0.91; /* SAMBA */
rho_epsilon=0.25; /* SAMBA */
rho_Upsilon=0.720;
rho_zetac=0.892;
rho_phitilde=0.85; /* SAMBA */
rho_lambdamc=0.970;
rho_lambdami=0.963;
rho_lambdax=0.886;
rho_R=0.761; /* FISCAL POLICY */
rho_pi=0.84; /* SAMBA */
rho_dpi=0.310;
rho_x=-0.1;
rho_y=0.16; /* SAMBA */
rho_dy=0.128;
rho_m = 0.976;
rho_ztildestar=0.992;


/* DECLARACION DE PARAMETROS ESTADO ESTACIONARIO */

b_w=(lambda_w*sigma_L-(1-lambda_w))/((1-beta*xi_w)*(1-xi_w));
eta_0=b_w*xi_w;
eta_1=(sigma_L*lambda_w-b_w*(1+beta*xi_w^2));
eta_2=b_w*beta*xi_w;
eta_3=-b_w*xi_w;
eta_4=b_w*beta*xi_w;
eta_5=b_w*xi_w*kappa_w;
eta_6=-b_w*beta*xi_w*kappa_w;
eta_7=(1-lambda_w);
eta_8=-(1-lambda_w)*sigma_L;
eta_9=-(1-lambda_w)*tau_y/(1-tau_y);
eta_10=-(1-lambda_w)*tau_w/(1+tau_w);


pi=mu/mu_z; //A.3
R=(pi*mu_z-tau_k*beta)/((1-tau_k)*beta);//A.2
R_f=R; //A.17
eta_mc=lambda_mc/(lambda_mc-1); //Substitution elasticity among imported consumption goods
eta_mi=lambda_mi/(lambda_mi-1);//Substitution elasticity among imported investment goods
gamma_id=((1-omega_i)+omega_i*(eta_mi/(eta_mi-1))^(1-eta_i))^(1/(1-eta_i)); //A.11
gamma_cd=((1-omega_c)+omega_c*(eta_mc/(eta_mc-1))^(1-eta_c))^(1/(1-eta_c)); //A.9
gamma_dc=1/gamma_cd;
gamma_cmc=((1-omega_c)*((eta_mc-1)/eta_mc)^(1-eta_c)+omega_c)^(1/(1-eta_c)); //A.10
gamma_mcc=1/gamma_cmc;
gamma_imi=((1-omega_i)*((eta_mi-1)/eta_mi)^(1-eta_i)+omega_i)^(1/(1-eta_i)); //A.12
gamma_mii=1/gamma_imi;
r_k=(mu_z*gamma_id-beta*(1-delta)*gamma_id)/((1-tau_k)*beta);//using A.6 in FOC for k_bar(2.54)
w_bar= (1-alpha)*lambda_d^(-1/(1-alpha))*alpha^(alpha/(1-alpha))*r_k^(-alpha/(1-alpha))*R_f^(-1);   //using A.19
k_H=alpha/(1-alpha)*mu_z*w_bar*R_f*r_k^(-1);//using A.16
D1=(1-omega_c)*gamma_cd^eta_c+omega_c*gamma_cmc^eta_c;
D2=(1-gr)/lambda_d*mu_z^(-alpha)*k_H^alpha-((1-omega_i)*gamma_id^eta_i+omega_i*gamma_imi^eta_i)*(1-(1-delta)/mu_z)*k_H;
D3=(((1-tau_y)/lambda_w*w_bar/(1+tau_w))/A_L)^(1/sigma_L);
D4=((mu_z-beta*b)/((1+tau_c)*(mu_z-b)))*gamma_cd^(-1);
H=(D3*D4^(1/sigma_L)*(D2/D1)^(-1/sigma_L))^(sigma_L/(1+sigma_L));
c=D2/D1*H;
psi_z=1/c*D4;
y_bar=1/lambda_d*(mu_z)^(-alpha)*(k_H)^alpha*H;
g=gr*y_bar;
q=(A_q/((1-tau_k)*psi_z*(R-1)))^(1/sigma_q);
m_bar=w_bar*H+q;
k=k_H*H;
k_bar=k;
i=(1-(1-delta)/mu_z)*k;
c_m =omega_c*gamma_cmc^eta_c*c;
i_m=omega_i*gamma_imi^eta_i*i;
y_star=omega_c*gamma_cmc^eta_c*c+omega_i*gamma_imi^eta_i*i;

// ///////////////////////////////// //
/* DEFINICION DEL MODELO */
// ///////////////////////////////// //

model (linear);

/* ///////////////////////  Original monetary policy rule (B22) /////////////////////// */
R_hat=rho_R*R_hat(-1)+(1-rho_R)*(pi_bar+rho_pi*(pi_c(-1)-pi_bar)+rho_y*y_hat(-1)+rho_x*x(-1))+rho_dpi*(pi_c-pi_c(-1))+rho_dy*(y_hat-y_hat(-1))+epsilon_R;
/* ///////////////////////////////////////////////////////////////////////// */

/*///////////////////////  Domestic Phillips Curve (B1) /////////////////////// */
pi_hat-pi_bar=beta/(1+kappa_d*beta)*(pi_hat(+1)-rho_pibar*pi_bar)+kappa_d/(1+kappa_d*beta)*(pi_hat(-1)-pi_bar)-(kappa_d*beta*(1-rho_pibar)/(1+kappa_d*beta))*pi_bar +(((1-xi_d)*(1-xi_d*beta))/(xi_d*(1+kappa_d*beta)))*(mc + lambda_dhat);
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// marginal cost /////////////////////// */
mc=alpha*(mu_zhat+H_hat-k_hat)+ w_barhat+R_fhat -epsilon;
/* ///////////////////////////////////////////////////////////////////////// */

/*/////////////////////// rental rate of capital /////////////////////// */
rk_hat=mu_zhat+w_barhat+R_fhat+H_hat-k_hat;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// gross effective nominal rate of interest paid by firms to finance wage bill in advance /////////////////////// */
R_fhat=R_hat(-1); //without money demand shock
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Phillips Curve for imported consumption goods (B2) /////////////////////// */
pi_mc-pi_bar=(beta/(1+kappa_mc*beta))*(pi_mc(+1)-rho_pibar*pi_bar)+(kappa_mc/(1+kappa_mc*beta))*(pi_mc(-1)-pi_bar)-(kappa_mc*beta*(1-rho_pibar)/(1+kappa_mc*beta))*pi_bar+(((1-xi_mc)*(1-xi_mc*beta))/(xi_mc*(1+kappa_mc*beta)))*(mc_mc +lambda_mchat);
mc_mc=-mc_x-gamma_xstar-gamma_mcdhat;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Phillips Curve for imported investment goods (B3) /////////////////////// */
pi_mi-pi_bar=(beta/(1+kappa_mi*beta))*(pi_mi(+1)-rho_pibar*pi_bar)+(kappa_mi/(1+kappa_mi*beta))*(pi_mi(-1)-pi_bar)-(kappa_mi*beta*(1-rho_pibar)/(1+kappa_mi*beta))*pi_bar+(((1-xi_mi)*(1-xi_mi*beta))/(xi_mi*(1+kappa_mi*beta)))*(mc_mi + lambda_mihat);
mc_mi=-mc_x-gamma_xstar-gamma_midhat;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Phillips Curve for exporting firm (B4) /////////////////////// */
pi_x-pi_bar=(beta/(1+kappa_x*beta))*(pi_x(+1)-rho_pibar*pi_bar)+(kappa_x/(1+kappa_x*beta))*(pi_x(-1)-pi_bar)-(kappa_x*beta*(1-rho_pibar)/(1+kappa_x*beta))*pi_bar+(((1-xi_x)*(1-xi_x*beta))/(xi_x*(1+kappa_x*beta)))*(mc_x + lambda_x);
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// wage equation (B5) /////////////////////// */
/* ///////////////////////  additive labour supply shock /////////////////////// */
w_barhat=-(1/eta_1)*(eta_0*w_barhat(-1)+eta_2*w_barhat(+1)+eta_3*(pi_hat-pi_bar)+eta_4*(pi_hat(+1)-rho_pibar*pi_bar)+eta_5*(pi_c(-1)-pi_bar)+eta_6*(pi_c-rho_pibar*pi_bar)+eta_7*psi_zhat+eta_8*H_hat+eta_9*tauy_hat + eta_10*tauw_hat) + zeta_h;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Euler equation (B6) /////////////////////// */
c_hat=-(1/(mu_z^2+b^2*beta))*(-b*beta*mu_z*c_hat(+1)-b*mu_z*c_hat(-1)+b*mu_z*(mu_zhat-beta*mu_zhat(+1))+(mu_z-b*beta)*(mu_z-b)*psi_zhat+tau_c/(1+tau_c)*(mu_z-b*beta)*(mu_z-b)*tauc_hat + (mu_z-b*beta)*(mu_z-b)*gamma_cdhat-(mu_z-b)*(-b*beta*zeta_c(+1))) + zeta_c;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Derivative w.r.t. Investment (B7) /////////////////////// */
i_hat=(1/((mu_z^2*S_tilde)*(1+beta)))*((mu_z^2*S_tilde)*(i_hat(-1)+beta*i_hat(+1)-mu_zhat+beta*mu_zhat(+1))+P_k-gamma_idhat)+Upsilon;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Derivative w.r.t. real balances (B8) /////////////////////// */
-mu*psi_zhat +mu*psi_zhat(+1)-mu*mu_zhat(+1)+(mu-beta*tau_k)*R_hat-mu*pi_hat(+1)+tau_k/(1-tau_k)*(beta-mu)*tauk_hat(+1)=0;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Derivative w.r.t. capital(B9) /////////////////////// */
psi_zhat+mu_zhat(+1)-psi_zhat(+1)-beta*(1-delta)/mu_z*P_k(+1)+P_k-(mu_z-beta*(1-delta))/mu_z*rk_hat(+1)+tau_k/(1-tau_k)*(mu_z-beta*(1-delta))/mu_z*tauk_hat(+1);
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// UIP condition (B10) /////////////////////// */
dS(+1)-(R_hat-Rstar_hat)-phi_a*a+phi_tilde=0;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Aggregate resource constraint (B11) /////////////////////// */
(1-omega_c)*gamma_cd^eta_c*c/y_bar*(c_hat+eta_c*gamma_cdhat)+(1-omega_i)*gamma_id^eta_i*i/y_bar*(i_hat+eta_i*gamma_idhat)+gr*g_hat+y_star/y_bar*(ystar_hat-eta_f*gamma_xstar+z_tildestar)=lambda_d*(epsilon+alpha*(k_hat-mu_zhat)+(1-alpha)*H_hat)-(1-tau_k)*r_k*k_bar/(y_bar*mu_z)*(k_hat-k_barhat(-1));
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Law of motion for capital (B12) /////////////////////// */
k_barhat=(1-delta)*1/mu_z*k_barhat(-1)-(1-delta)*(1/mu_z)*mu_zhat+(1-(1-delta)*1/mu_z)*i_hat+Upsilon;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Deriative w.r.t. cash holding (B14) /////////////////////// */
q_hat=1/sigma_q*(tau_k/(1-tau_k)*tauk_hat-psi_zhat-R/(R-1)*R_hat(-1)); //without money demand shock
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Money growth (B15) /////////////////////// */
mu_hat-m_barhat-mu_zhat-pi_hat+m_barhat(-1)=0;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// loan market clearing condition (B16) /////////////////////// */
w_bar*H*(w_barhat+H_hat)=mu*m_bar/(pi*mu_z)*(mu_hat+m_barhat(-1)-pi_hat-mu_zhat)-q*q_hat; //without firm money demand shock
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// net foreign assets (B17) /////////////////////// */
a=-y_star*mc_x-eta_f*y_star*gamma_xstar+y_star*ystar_hat+y_star*z_tildestar+(c_m+i_m)*gamma_fhat-(c_m*(-eta_c*(1-omega_c)*(gamma_cd)^(-(1-eta_c))*gamma_mcdhat +c_hat)+i_m*(-eta_i*(1-omega_i)*(gamma_id)^(-(1-eta_i))*gamma_midhat+i_hat))+R/(pi*mu_z)*a(-1);
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// relative prices (B18-B21) /////////////////////// */
gamma_mcdhat=gamma_mcdhat(-1)+pi_mc-pi_hat;
gamma_midhat=gamma_midhat(-1)+pi_mi-pi_hat;
gamma_xstar=gamma_xstar(-1)+pi_x-pistar_hat;
mc_x=mc_x(-1)+pi_hat-pi_x-dS;
gamma_fhat=mc_x+gamma_xstar;
gamma_cdhat=omega_c*(gamma_mcc)^(1-eta_c)*gamma_mcdhat; 
gamma_idhat=omega_i*(gamma_mii)^(1-eta_i)*gamma_midhat;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// CPI_Inflation /////////////////////// */
pi_c=((1-omega_c)*(gamma_dc)^(1-eta_c))*pi_hat+((omega_c)*(gamma_mcc)^(1-eta_c))*pi_mc;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Deviation of output from SS /////////////////////// */
y_hat=lambda_d*(epsilon+alpha*(k_hat-mu_zhat)+(1-alpha)*H_hat);
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// real exchange rate /////////////////////// */
x=-omega_c*(gamma_cmc)^(-(1-eta_c))*gamma_mcdhat-gamma_xstar-mc_x;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// employment equation (B23) /////////////////////// */
E=beta/(1+beta)*E(+1)+(1/(1+beta))*E(-1)+((1-xi_e)*(1-beta*xi_e))/((1+beta)*xi_e)*(H_hat-E);
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// FOC w.r.t Capital utilization rate (B13) /////////////////////// */
u=1/sigma_a*rk_hat-(1/sigma_a)*(tau_k/(1-tau_k))*tauk_hat;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// Capital utilization rate /////////////////////// */
u=k_hat-k_barhat(-1);
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// VAR POLITICA FISCAL /////////////////////// */

 tauk_hat    = rho_tauk*tauk_hat(-1)    + epsilon_tauk;
 tauw_hat    = rho_tauw*tauw_hat(-1)    + epsilon_tauw; 
 tauy_hat    =   FisLag111*tauy_hat(-1)   + FisLag112*tauc_hat(-1) + FisLag113*g_hat(-1)   
               + FisLag211*tauy_hat(-2)   + FisLag212*tauc_hat(-2) + FisLag213*g_hat(-2) 
               + epsilon_tauy;
 
 tauc_hat    =   FisLag121*tauy_hat(-1)   + FisLag122*tauc_hat(-1) + FisLag123*g_hat(-1)   
               + FisLag221*tauy_hat(-2)   + FisLag222*tauc_hat(-2) + FisLag223*g_hat(-2) 
               + epsilon_tauc;
 
 g_hat       =   FisLag131*tauy_hat(-1)   + FisLag132*tauc_hat(-1) + FisLag133*g_hat(-1)   
               + FisLag231*tauy_hat(-2)   + FisLag232*tauc_hat(-2) + FisLag233*g_hat(-2) 
               + epsilon_rhog; 
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// VAR RESTO DEL MUNDO /////////////////////// */

 pistar_hat  = ForLag111*pistar_hat(-1)  + ForLag112*ystar_hat(-1) + ForLag113*Rstar_hat(-1)  
             +ForLag211*pistar_hat(-2)  + ForLag212*ystar_hat(-2) + ForLag213*Rstar_hat(-2) 	
             +ForLag311*pistar_hat(-3)  + ForLag312*ystar_hat(-3) + ForLag313*Rstar_hat(-3) 
      		+ForLag411*pistar_hat(-4)  + ForLag412*ystar_hat(-4) + ForLag413*Rstar_hat(-4) + epsilon_pistar;
 
 ystar_hat = ForLag121*pistar_hat(-1)  + ForLag122*ystar_hat(-1) + ForLag123*Rstar_hat(-1)  
             +ForLag221*pistar_hat(-2)  + ForLag222*ystar_hat(-2) + ForLag223*Rstar_hat(-2) 	
             +ForLag321*pistar_hat(-3)  + ForLag322*ystar_hat(-3) + ForLag323*Rstar_hat(-3) 
      		+ForLag421*pistar_hat(-4)  + ForLag422*ystar_hat(-4) + ForLag423*Rstar_hat(-4) + epsilon_ystar;
 
 Rstar_hat  = ForLag131*pistar_hat(-1)  + ForLag132*ystar_hat(-1) + ForLag133*Rstar_hat(-1)  
             +ForLag231*pistar_hat(-2)  + ForLag232*ystar_hat(-2) + ForLag233*Rstar_hat(-2) 	
             +ForLag331*pistar_hat(-3)  + ForLag332*ystar_hat(-3) + ForLag333*Rstar_hat(-3) 
      		+ForLag431*pistar_hat(-4)  + ForLag432*ystar_hat(-4) + ForLag433*Rstar_hat(-4) + epsilon_Rstar;
/* ///////////////////////////////////////////////////////////////////////// */

/* /////////////////////// AR(1) PARA SIMULAR SHOCKS /////////////////////// */

lambda_dhat=epsilon_lambdad;
lambda_mchat=rho_lambdamc*lambda_mchat(-1)+epsilon_lambdamc;
lambda_mihat=rho_lambdami*lambda_mihat(-1)+epsilon_lambdami;
lambda_x=rho_lambdax*lambda_x(-1)+epsilon_lambdax;
mu_zhat=rho_muz*mu_zhat(-1)+epsilon_muz;
epsilon=rho_epsilon*epsilon(-1)+epsilon_epsilon; 
Upsilon=rho_Upsilon*Upsilon(-1)+epsilon_Upsilon;
zeta_c=rho_zetac*zeta_c(-1)+epsilon_zetac; 
phi_tilde=rho_phitilde*phi_tilde(-1)+epsilon_phitilde; 
pi_bar=rho_pibar*pi_bar(-1)+epsilon_pibar;
z_tildestar=rho_ztildestar*z_tildestar(-1)+epsilon_ztildestar;
mu_hat = rho_m*mu_hat(-1) + epsilon_m;







/* ///////////////////////////////////////////////////////////////////////// */

end;

// ///////////////////////////////// //
/* DECLARACION DE LOS SHOCKS */
// ///////////////////////////////// //

shocks;

/* var epsilon_tauk; stderr 1; */ /* capital income tax shock */

/* var epsilon_tauw; stderr 1; */ /* pay-roll  tax shock 

/* var epsilon_tauc; stderr 1;  */  /* comsumption tax shock */

/*  var epsilon_tauy; stderr 1; */  /* labour income tax shock  */

/* var epsilon_rhog; stderr 1; */  /* government spending 

/* var epsilon_pistar; stderr 1; */   /* Foreign inflation */

 /* var epsilon_ystar; stderr 1; */   /* Foreign output */

/*  var epsilon_Rstar; stderr 1;  */  /* Foreign interest rate */

/* var epsilon_lambdad; stderr 1;  */ /* domestic markup */

/* var epsilon_lambdamc; stderr 1;  */ /* consumption import markup */

/* var epsilon_lambdami; stderr 1;  */ /* investment import markup */

/* var epsilon_lambdax; stderr 1;  */ /* export markup */

 var epsilon_muz; stderr 1;  /* non-stationary technology growth */

 var epsilon_epsilon; stderr 1;   /* stationary technology */

/*  var epsilon_Upsilon; stderr 1; */    /* investment specific technology shock 

 /* var epsilon_zetac; stderr 1; */   /* consumption preference shock */

  var epsilon_phitilde; stderr 1;   /* risk premium shock */

 /* var epsilon_R; stderr 1; */  /* monetary policy shock */

 var epsilon_pibar; stderr 1;    /* inflation target shock */

 var epsilon_m; stderr 1;   /* M1 */

 /* var epsilon_ztildestar; stderr 1; */  /* foreign risk premium shock */





end;

check;
steady;

/* ****************************************************************** */
/* **************** BAYESIAN ESTIMATION ***************************** */
/* ****************************************************************** */


estimated_params;


/* eta_f, inv_gamma_pdf, 1, 2; */
/* eta_i, inv_gamma_pdf, 1, 2; */
/* lambda_d, inv_gamma_pdf, 2, 2;  */
/* lambda_mc, inv_gamma_pdf, 0.5, 2; */ 
/* lambda_mi, inv_gamma_pdf, 0.5, 2; */  
/* lambda_w, inv_gamma_pdf, 0.5, 2; */


xi_d, beta_pdf, 0.5, 0.1; 
xi_e, beta_pdf, 0.7, 0.1; 
xi_mc, beta_pdf, 0.5, 0.1; 
xi_mi, beta_pdf, 0.5, 0.1; 
xi_w, beta_pdf, 0.7, 0.1; 
xi_x, beta_pdf, 0.9, 0.1; 


stderr epsilon_muz,  inv_gamma_pdf, 0.1, 1;
/* stderr epsilon_R,  inv_gamma_pdf, 0.25, 1; */
 stderr epsilon_phitilde,  inv_gamma_pdf, 0.25, 1; 
 stderr epsilon_pibar,  inv_gamma_pdf, 0.5 , 1; 
stderr epsilon_m,  inv_gamma_pdf, 0.1, 1;
/* stderr epsilon_tauk, inv_gamma_pdf, 0.21, 1; */
/* stderr epsilon_tauw, inv_gamma_pdf, 0.21, 1; */ 
/* stderr epsilon_tauc, inv_gamma_pdf, 0.21, 1; */
/* stderr epsilon_tauy, inv_gamma_pdf, 0.25, 1; */
/* stderr epsilon_rhog, inv_gamma_pdf, 0.1, 1; */
 /* stderr epsilon_pistar, inv_gamma_pdf, 0.1, 1; */
 /* stderr epsilon_ystar, inv_gamma_pdf, 0.1, 1;  */
/* stderr epsilon_Rstar, inv_gamma_pdf, 0.1, 1; */
/* stderr epsilon_lambdad, inv_gamma_pdf, 0.25, 1; */
/* stderr epsilon_lambdamc, inv_gamma_pdf, 0.25, 1; */
/* stderr epsilon_lambdami, inv_gamma_pdf, 0.25, 1; */
/* stderr epsilon_lambdax, inv_gamma_pdf, 0.25, 1; */
 stderr epsilon_epsilon, inv_gamma_pdf, 0.1, 1; 
/* stderr epsilon_Upsilon, inv_gamma_pdf, 0.5, 1; */
/* stderr epsilon_zetac, inv_gamma_pdf, 0.1, 1; */
 /* stderr epsilon_ztildestar, inv_gamma_pdf, 0.8, 1; */

end;

estimated_params_init;

 /* eta_f, 1;  */
/*  eta_i,  1; */
/* lambda_d, 2;  */
/* lambda_mc,  0.5; */
/*lambda_mi,  0.5; */
/* lambda_w,  0.5; */



xi_d,  0.5; xi_e,  0.7; 
xi_mc,  0.5; xi_mi,  0.5; 
xi_w,  0.7;  xi_x,  0.9;  


stderr epsilon_muz,   0.1;
/* stderr epsilon_R,   0.25; */
 stderr epsilon_phitilde,   0.25; 
stderr epsilon_pibar,   0.5 ; 
stderr epsilon_m,   0.1;
/* stderr epsilon_tauk, 0.1; */
/* stderr epsilon_tauw, 0.1; */
/* stderr epsilon_tauc, 0.1; */
/* stderr epsilon_tauy, 0.25; */
/* stderr epsilon_rhog, 0.1; */
 /* stderr epsilon_pistar, 0.1; */
/* stderr epsilon_ystar, 0.1; */
/* stderr epsilon_Rstar, 0.1; */
/* stderr epsilon_lambdad, 0.25; */
/* stderr epsilon_lambdamc, 0.25; */
/* stderr epsilon_lambdami, 0.25; */
/* stderr epsilon_lambdax, 0.25; */
  stderr epsilon_epsilon, 0.1;  
/*  stderr epsilon_Upsilon, 0.5; */
 /* stderr epsilon_zetac, 0.1; */
 /* stderr epsilon_ztildestar, 0.8; */

end;




varobs c_hat	i_hat	mu_hat	y_hat  g_hat;

estimation(datafile=Input5,mode_check,
first_obs=2,nobs=65,mode_compute=4,mh_replic=2000,
mh_jscale=1.5,mh_nblocks=1,bayesian_irf,irf=50);




