% Ireland(2010) Replication 
%
% Guidon Fenig

% close all;
%----------------------------------------------------------------
% 1. Defining variables
%----------------------------------------------------------------

var a lambda y z r pi e g inflation interest output Z_au;

varexo ea ee ez er ;

parameters beta gamma alpha psi rhop rhog rhoa rhoe zeta;

%----------------------------------------------------------------
% 2. Estimated Parameters (By Maximum likelihood in the paper)
%----------------------------------------------------------------

gamma=0.3;       //habit formation parameter
alpha=0.05;             //indexation parameter, for alfa=0 the price setting is purely forward looking
rhop=0.25;       //response coefficient of the Taylor rule
rhog=0.25;        //response coefficient of the Taylor rule
rhoa=0.75;        //persistence in the preference shock
rhoe=0.25;             //persistence in the renormalized cost-push shock

%----------------------------------------------------------------
% 3. Calibrated parameters
%----------------------------------------------------------------
zeta=1.0046;        //drift of the AR(1) technology process
beta=0.75;        //discount factor
psi=0.10;           //Phillips Curve parameter; equals the original model parameters (theta-1)/phi


%----------------------------------------------------------------
% 3. Model
%----------------------------------------------------------------

model(linear); 

//law of motion for the preference shock
a=rhoa*a(-1)+ea;

//marginal utility of consumption in terms of past, present and expected future output with habit formation in preferences
lambda*(zeta-beta*gamma)*(zeta-gamma)=zeta*gamma*y(-1)-(zeta^2+(beta*(gamma^2)))*y+beta*gamma*zeta*y(+1)+(zeta-gamma)*(zeta-beta*gamma*rhoa)*a-gamma*zeta*z;

//IS curve
lambda=r+lambda(+1)-pi(+1);

//law of motion for the technology shock
z=ez;

//law of motion for the renormalized cost-push shock 
e=rhoe*e(-1)+ee;

//New Keynesian Phillips Curve
(1+alpha*beta)*pi=psi*a-psi*lambda+alpha*pi(-1)+beta*pi(+1)+e;

//monetary policy rule
r=r(-1)+rhop*pi+rhog*g+er;

//growth rate of output
g=y-y(-1)+z;

//annualized inflation and interest rate
inflation=pi*4;
interest=r*4;

//output and outputgap in levels
Z_au=z+Z_au(-1);
output=y+Z_au;

end;

%----------------------------------------------------------------
% 4. Computation
%----------------------------------------------------------------

steady;
check;


%----------------------------------------------------------------
% 5. Shocks
%----------------------------------------------------------------

shocks;
var ea=(0.0868*100)^2;      //preference shock
var ee=(0.0017*100)^2;      //renormalized cost-push shock
var ez=(0.0095*100)^2;      //technology shock
var er=(0.0014*100)^2;      //monetary policy shock
end;

%----------------------------------------------------------------
% 6. Variables from data
%----------------------------------------------------------------

varobs inflation interest output;


%----------------------------------------------------------------
% 7. Prior Distributions
%----------------------------------------------------------------

estimated_params;
beta,beta_pdf,0.75,0.25;
psi , normal_pdf,0.1,1; 
gamma,beta_pdf,0.3,0.1;
alpha,beta_pdf,0.05,0.1;
rhop ,  beta_pdf,0.25,0.15; 
rhog ,  beta_pdf,0.25,0.15; 
rhoa ,  beta_pdf,0.75,0.15; 
rhoe ,  beta_pdf,0.25,0.15; 
stderr ea,inv_gamma_pdf,1,inf; 
stderr ee,inv_gamma_pdf,1,inf; 
stderr ez,inv_gamma_pdf,1,inf; 
stderr er,inv_gamma_pdf,1,inf;
end;


%----------------------------------------------------------------
% 8. Bayesian Etimation
%----------------------------------------------------------------

estimation (datafile=Data_Ireland2,order=1, mh_replic=2000,mh_nblocks=2,mh_drop=0.45,mh_jscale=0.4,mode_compute=6, forecast=4,filter_decomposition,bayesian_irf, irf=12) inflation interest output;







