% Thomas Dengler, 2016
% Dynare code for:
% Trigari(2009) "Equilbirium Unemployment, Job Flows and Inflation Dynamics", 
% Journal of Money, Credit and Banking, Blackwell Publishing, vol. 41(1), pages 1-33, 02.
            
 
var i r pie y lambda c x h m u v s theta jc jd a n q w nbar;
parameters etafa rhom gammapi gammay beta e sub kappa b omega eps rho xi alpha rhox q_ss x_ss sigma eta ha mya sigmaa fa psi phil phia phib phic a_ss lambda_ss u_ss s_ss n_ss va vb w_ss h_ss fa_p c_ss y_ss m_ss kappa_h;

varexo ei;  

rhom    = 0.85;           // interest rate smoothin parameter
gammapi = 1.5;            // response coefficient to inflation
gammay  = 0.5;            // response coefficient to output
beta    = 0.99;           // discount factor
e       = 0.55;           // habit persistence parameter
sub     = 10;             // (inverse) intertemp. rate of substitution of leisure
omega   = 0.5;            // fraction of backward looking retailers
eps     = 11;             // markup
rho     = 0.08;           // overall separation rate
alpha   = 0.68;           // rate at which separations are reposted
rhox    = alpha*rho;      // exog. separation rate (only exogenous separations are reposted)
sigma   = 0.55;           // elasticity of new matches w.r.t. search. workers
eta     = 0.5;            // relative bargaining power
mya     = 0;              // determines threshold-value of a
sigmaa  = 0.42;           // determines threshold-value of a
etafa   = 0.17;
x_ss    = (eps-1)/eps;     //ss marginal costs
q_ss    = 0.7;            // steady state prob. that firms will fill a vacancy
n_ss    = 0.75;          // ss employment rate
h_ss    = 1;             // ss hours worked
psi     = 0.85;           // probability that firm does not change its price


phil = psi + omega*(1-psi*(1-beta));         //phillips curve stuff
phia = (1-beta*psi)*(1-psi)*(1-omega)/phil;
phib = beta*psi/phil;
phic = omega/phil;

//other derived steady state values and parameters 

y_ss      = n_ss*(1-rho)*h_ss;
c_ss      = y_ss;
u_ss      = 1-(1-rho)*n_ss;		                   //amount of searching workers
lambda_ss = (1-beta*e)/(c_ss*(1-e));               // marginal utility of consumption
m_ss      = n_ss -(1-rho)*n_ss;                    //matches
s_ss      = m_ss/u_ss;                             //job finding probability
fa        = (1-rho)/(1-rhox);                      //cdf of labor disutility shock/The fraction of employees who don't separate endogenously
a_ss      = 2.2;                                   //treshold value of shock abar that yields the fa 
fa_p      = 0.0741;                                //pdf of shock evaluated at abar, follows from fa 
ha        = 1.0130;                                //partial expectation of shock, follows from fa

kappa_h   = (x_ss*lambda_ss)/(h_ss^sub);                //parameter in labor disutility

kappa     = q_ss*beta*(1-rho)*(1-eta)*(a_ss-ha/fa);                      // vacancy costs
b         = x_ss*h_ss - ((kappa_h/(1+sub))*h_ss^(1+sub)+a_ss)/lambda_ss+((1-eta*s_ss)/(1-eta))*kappa/(lambda_ss*q_ss);
w_ss      = kappa/(h_ss*lambda_ss*q_ss)*(1-1/(beta*(1-rho)))+x_ss;                                 // ss wage

va  = (sub/(1+sub))*x_ss*lambda_ss*h_ss*(a_ss-(ha/fa))^(-1);    
vb  = (a_ss-ha/fa)^(-1)*lambda_ss*(x_ss*h_ss*(10/(1+sub))-b);

xi  = (sub/(1+sub))*x_ss*(1-eta)*h_ss;   

model(linear);
// Taylor rule
i=rhom*i(-1)+(1-rhom)*gammapi*pie+(1-rhom)*gammay*y+ei;
 
// Euler equation
lambda=lambda(+1)+r;

// Marginal utility of consumption 
(1-beta*e)*lambda=(e/(1-e))*c(-1)-((1+beta*(e^2))/(1-e))*c+((beta*e)/(1-e))*c(+1);
 
// Real interest rate
r=i-pie(+1);
 
// Hours per worker
x=(sub*h)-lambda;

// Phillips Curve
pie=phia*x+phib*pie(+1)+phic*pie(-1);
 
// Resource constraint
y=c;
 
// Market clearing
y=h+n(-1)+etafa*a;
 
// Matching function
m=sigma*u+(1-sigma)*v;
 
// Transition probability1 - vacancy filling rate
q=m-v;
 
// Transition probability2 - job finding rate
s=m-u;
 
// Market tightness
theta=v-u;
 
// Employment
n=(1-rho)*n(-1)+(1-rho)*etafa*a+rho*m;
 
// Searching workers
u=-(n_ss/u_ss)*(1-rho)*(n(-1)+etafa*a);

//Vacancy posting condition
q=-va*(x(+1)+h(+1))+(beta*(1-rho)*eta*s_ss*theta(+1))+(beta*(1-rho)*q(+1))-(vb)*lambda(+1);

//wage equation
w=(1/(w_ss*h_ss))*(((1+eta*sub)/(1+sub))*x_ss*h_ss*(x+h) + (eta*kappa*s_ss/(lambda_ss*q_ss))*theta -(eta*kappa*s_ss/(lambda_ss*q_ss)+ha/(lambda_ss*fa))*lambda +(a_ss/lambda_ss)*(a_ss*fa_p/fa-fa_p*ha/(fa^2))*a)-h;
     
//Separation Condition
xi*(x+h)-((1-eta)*(a_ss/lambda_ss))*(a-lambda)-((eta*s_ss*kappa)/(q_ss*lambda_ss))*theta-(kappa/(q_ss*lambda_ss))*q-(kappa/(q_ss*lambda_ss))*lambda+((eta*s_ss*kappa)/(q_ss*lambda_ss))*lambda=0;

//Job creation rate
jc=((1/(1-alpha*q_ss))*(m-n(-1)))+(1-(1/(1-alpha*q_ss)))*q;

//Job destruction rate
jd=-(1/(1-alpha*q_ss))*((1-rho)/rho)*etafa*a+(1-(1/(1-alpha*q_ss)))*q;

//Effective employment
nbar=n(-1)+etafa*a; 

end;
resid(1);
steady;
check;
resid;
 
shocks;
var ei; stderr 0.25;
end;
 
//stoch_simul(order=1, periods=500);
stoch_simul(order=1, irf =21) y pie jd jc nbar w x h c lambda i r n u v a q s w  theta;


