// New-Keynesian model Labor market frictions (with sticky price)
// Zeinab Fathy (2015)
// ===================================================================
// Quarterly frequency
// Annualized rates of change

// ENDOGENOUS VARIABLES
var   MC                                                                   // Marginal cost
      W_real                                                               // real wage 
      C                                                                    // consumption
      N                                                                    // employment
      x                                                                    // labor market tightness (ratio of aggregate hires to unemployment)
      A                                                                    // AR (1) Productivity process
      R                                                                    // Nominal interest rate
      Pi;                                                                  // inflation


// EXOGENOUS VARIABLES
varexo eps_A;                                                              //productivity shock

//=================================
//      The parametrs:
//=================================
Parameters  eps gamma rhoa chi Phi M delta B alpha beta Phi_Pi thetavariant THETA Psi; 

eps         = 6.00;                                                        //Elasticity of substitution (CES) between final goods
gamma       = 0.5;                                                         //index of wage rigidities 
rhoa        = 0.9;                                                         //productivity Shock (Persistence of Shock)
chi         = 1.03;                                                        //Porportional to the MRS between labor and consumption(From part of flexible wage)
Phi         = 1.00;                                                        //Inverse of the Frish elasticity of labor supply
M           = eps/(eps-1);                                                 //Gross markup of final-good firms 
delta       = 0.12;                                                        //job Seperation rate
B           = 0.12;                                                        //Hiring cost constant
alpha       = 1.00;                                                        //Hiring-cost elasticity WRT labor-market tightness                   
beta        = 0.99;                                                        //Discount Factor
Phi_Pi      = 5;                                                           //from eq of central bank instrument
thetavariant= 1;                                                           //workers relative bargaining share
theta_P     = 0.60;                                                        //Calvo Parameter
Psi         = (eps-1)*theta_P/((1-theta_P)*(1-beta*theta_P));              //Rotemberg sticky price parameter
THETA       = 0.822514;                                                    //from part real wage


//======================================
//  The Model (First order conditions)
//======================================
Model;
//Productivity Shock
log(A)      = rhoa*log(A(-1))+eps_A;                                       

//Real wage rigidities
W_real      = THETA*A^(1-gamma);                                           

//Job creation equation 
chi*C*N^Phi = (A/M)-((1+thetavariant)*A*B*x^alpha)+beta*(1-delta)*((C/C(+1))*A(+1)*B*x(+1)^alpha*(1+thetavariant*(1-x(+1)))); 

//Market clear condition (Resource constraint)
C           = (A*N)-((A*B*x^alpha)*(N-(1-delta)*N(-1))); 
//Euler equation (Consumer problem)
1/R         = beta*((C/C(+1))/Pi(+1));                                     

//Employment
N           = (1-delta)*N(-1)+x*(1-(1-delta)*N(-1));                       

//Taylor rule
R           = (1/beta)*Pi^(Phi_Pi);                                        

//Phillip Curve
Psi*Pi*(Pi-1)= 1-eps*(1-MC)+beta*Psi*(Pi(+1)*(Pi(+1)-1)*((A(+1)*N(+1))/(A*N))*(C/C(+1)));      


                            
end;
        
//===============================
//  Define shock variances
//===============================
shocks;
var eps_A; stderr 0.01;

end;

//======================================
//  Initial Values for steady state
//======================================
initval;
A           = 1; 
Pi          = 1;                                                                   
R           = 1/beta;
W_real      = THETA*A^(1-gamma);
x           = 0.7;    
N           = (x/(delta+x-delta*x));
C           = (A*N)-(A*B*x^alpha); 
MC          = (eps-1)/eps;                                                     

end;

steady;
check;

stoch_simul(order = 2, hp_filter =1600,irf = 40);
