% Dynare program to get a second order approximation of the NC_EF_FG model

var kh_1 kf_1 kh_2 kf_2 c_1 c_2 a_1 a_2 cash_1 cash_2 ret_1 ret_2 wage_1 wage_2 Rh_1 Rf_1 Rh_2 Rf_2 tau_l_1 tau_l_2 K_1 K_2 Y_1 Y_2 dep_1 dep_2;
         
varexo e_1 e_2;

parameters rho_1 delta_1 rho_2 delta_2 grp1 alph L_bar G_1 G_2 dep_bar_1 dep_bar_2 sigma_1 sigma_2 corr_s;

% preference parameters
rho_1 = 5.0;
delta_1 = 0.9975;
rho_2 = 5.0;
delta_2 = 0.9975;

%production parameters
grp1 = 0.5;
alph = 0.34;
dep_bar_1 = 0.08;
dep_bar_2 = 0.08;
sigma_1 = 0.1;
sigma_2 = 0.1;
corr_s = 0.0; 

% labour
L_bar = 1.0;

% the government budget
G_1 = 0.025;
G_2 = 0.025;

model;
a_1 = kh_1/(kh_1+kf_1);
a_2 = kh_2/(kh_2+kf_2);
K_1=kh_1+kf_1;
K_2=kh_2+kf_2;

ret_1 =  (alph*(K_1(-1)/L_bar)^(alph-1.0));
ret_2 =  (alph*(K_2(-1)/L_bar)^(alph-1.0));
Rh_1 = 1.0+ret_1-dep_1;
Rf_1 = 1.0+ret_2-dep_2;
Rh_2 = 1.0+ret_2-dep_2;
Rf_2 = 1.0+ret_1-dep_1;

wage_1 = (1.0-alph)*((K_1(-1)/L_bar)^alph);
wage_2 = (1.0-alph)*((K_2(-1)/L_bar)^alph);

cash_1=(1.0-tau_l_1)*wage_1*L_bar+Rh_1*kh_1(-1)+Rf_1*kf_1(-1);
cash_2=(1.0-tau_l_2)*wage_2*L_bar+Rh_2*kf_2(-1)+Rf_2*kh_2(-1);
c_1 = cash_1-kh_1-kf_1;
c_2 = cash_2-kh_2-kf_2;

(c_1^(-rho_1)) = delta_1*(c_1(+1)^(-rho_1))*(Rh_1(+1));
(c_1^(-rho_1)) = delta_1*(c_1(+1)^(-rho_1))*(Rf_1(+1));
(c_2^(-rho_2)) = delta_2*(c_2(+1)^(-rho_2))*(Rh_2(+1));
(c_2^(-rho_2)) = delta_2*(c_2(+1)^(-rho_2))*(Rf_2(+1));

G_1= tau_l_1*wage_1*L_bar;
G_2= tau_l_2*wage_2*L_bar;

Y_1= (K_1(-1)^alph)*(L_bar^(1-alph));
Y_2= (K_2(-1)^alph)*(L_bar^(1-alph));

dep_1=dep_bar_1+e_1;
dep_2=dep_bar_2+e_2;

end; 

initval;

Rh_1=1.0/delta_1;
Rh_2=1.0/delta_2;

Rf_1=Rh_1;
Rf_2=Rh_2;

ret_1=(Rh_1-1.0)+dep_bar_1;
ret_2=(Rh_2-1.0)+dep_bar_2;

K_1=(ret_1/alph)^(1.0/(alph-1.0));
K_2=(ret_2/alph)^(1.0/(alph-1.0));

kh_1=K_1;
kf_1=0.0;
kh_2=K_2;
kf_2=0.0;

a_1 = kh_1/(kh_1+kf_1);
a_2 = kh_2/(kh_2+kf_2);

wage_1 = (1.0-alph)*((K_1/L_bar)^alph);
wage_2 = (1.0-alph)*((K_2/L_bar)^alph);

tau_l_1=(G_1)/wage_1;
tau_l_2=(G_2)/wage_2;

cash_1=(1.0-tau_l_1)*wage_1*L_bar+Rh_1*kh_1+Rf_1*kf_1;
cash_2=(1.0-tau_l_2)*wage_2*L_bar+Rh_2*kf_2+Rf_2*kh_2;

c_1 = cash_1-kh_1-kf_1;
c_2 = cash_2-kh_2-kf_2;

Y_1= (K_1^alph)*(L_bar^(1-alph));
Y_2= (K_2^alph)*(L_bar^(1-alph));

dep_1=dep_bar_1;
dep_2=dep_bar_2;
end; 

steady;

shocks;
var e_1 = sigma_1^2;
var e_2 = sigma_2^2;
var e_1, e_2 = corr_s;
end;

stoch_simul(order=1);
















  





