 var rho rho_n n u theta m q p v h w y e_bar h_bar H;

%rho: total separation rate, rho_n: endogenous job destruction rate, n: employment, u: searching workers, theta:labor market tightness
%m: matches, q: vacancy filling rate, p: job finding rate, v: posted vacancies, h=hours worked, y=output, e_bar=job destruction threshold
%h_bar=hours worked by "e_bar productivity types", H=expected productivity level conditional that it greater than "e_bar"


varexo e;

parameters rho_x sigma kappa phi bet f eta sigma_m b mu sd;

%rho_x: exogenous job destruction rate, sigma=elasticities of new matches, kappa= cost of keeping vacancy open, phi=frisch elasticity, bet=discount factor
%f: firing costs, eta=workers bargaining power, sigma_m=efficiency of matching technology, b=unemployment benefit, mu=mean of lognormal productivity distribution 
%sd=standard deviation of lognormal productivity distribution

rho_x=0.027;
sigma=0.5;
kappa=0.1010;
phi=10;
bet=0.99;
f=0.1;
eta=0.5;
sigma_m=0.4583;
b=1.0108;
mu=0;
sd=0.1;


external_function(name=integral_F, nargs=1, first_deriv_provided=areaF);
external_function(name=integral_H, nargs=1, first_deriv_provided=deriv_H);


model;
rho_n=integral_F(e_bar);
%probability of endogenously destruct a match
H=integral_H(e_bar);
rho=rho_x+(1-rho_x)*rho_n;
%total job separation rate as function of end. and exog. separation rates
n=(1-rho_n)*((1-rho_x)*n(-1)+m);
%employment dynamics
u=1-(1-rho_x)*n(-1);
%searching workers
theta=v/u;
m=sigma_m*(u^sigma)*(v^(1-sigma));
q=sigma_m*(theta^(-sigma));
p=sigma_m*(theta^(1-sigma));
kappa/(bet*q)=H(+1)*h(+1)-w(+1)*h(+1)*(1-rho_n(+1))+(1-rho_n(+1))*(1-rho_x)*kappa/q(+1)-rho_n(+1)*f;
%vacancy posting condition

h=H^(1/phi);
h_bar=e_bar^(1/phi);
%this is ancillar to job destruction condition
w=(eta*(h*H+kappa*theta-(1-p-rho_x)*bet*rho_n(+1)*f)+(1-eta)*((h^(1+phi))/(1+phi)+b))/h;
y=H*h*n-kappa*v-rho_n*f+e;
%output
e_bar*h_bar-b-(h_bar^(1+phi))/(1+phi)-bet*f*rho_n(+1)*(1-p-rho_x)*eta/(1-eta)+kappa*(1-eta*p-rho_x)/(q*(1-eta))=0;
%job destruction condition
end;

initval;
rho=0.1;
rho_n=0.075;
m=0.0811;
v=0.1158;
u=0.2703;
n=0.75;
p=0.3;
q=0.7;
theta=0.4286;
h=1.0019;
w=1.0808;
y=0.7505;
e_bar=0.8659;
h_bar=0.9857;
H=1.0193;

end;
 check;

steady ;


