//DYNARE CODE

//VARIABLE DECLARATION

var g c r n pi y w i b k q r_k t my_p_hat; 

varexo e_g;

//PARAMETER DECLARATION

parameters alpha beta gamma gamma_c gamma_g gamma_i delta eta theta theta_n theta_tau lambda lambda_p my_p rho rho_g sigma phi phi_b phi_g phi_pi omega;

//INITIAL PARAMETER CALIBRATION

alpha=0.33;             //Elasticity of output with respect to capital
beta=0.99;              //Household discount factor
gamma_i=0.2;               //Share of investment to output in steady state 
gamma_g=0.2;             //Share of government purchase to output in stedy state
delta=0.025;           //Depreciation rate of capital
eta=1;                 //The elasticity of incestement wrt q
theta=0.75;            //Fraction of firms that keep their price constant           
lambda=0.5;           //Amount of Non-Ricardian households
my_p=0.2;             //teady state price markup
phi=0.2;              // Elasticity of wages wrt hours
phi_pi=1.5;           //The response of the monetary authority to inflation
omega=-log(beta);
gamma_c=0.7984;       //1-gamma_g-delta*alpha/(rho+delta)*my_p;
lambda_p=0.7525;       //(1-beta*theta)*(1-theta)/theta
rho=1.0101;            //beta^(-1)

//parameters describing the fiscal policy rule
phi_b=0.33;
phi_g=0.10;
rho_g=0.9;

//parameter generated for solution of the model
sigma=0.6748;           //(1-lambda)*gamma*(my_p*phi*gamma_c+(1-alpha)) 
theta_tau=0.0060;       //lambda*gamma*mu_p*phi
theta_n=0.0428;         //lambda*gamma*(1-alpha)*(1-phi)*phi;
gamma=0.2999;            //1/(mu_p*phi*gamma_c+(1-alpha))*(1-lambda)*(1+phi)


//MODEL
//ALL EQUATIONS ARE STATED IN LOG FORM

model;
//Tobins q
q=beta*q(+1)+(1-beta*(1-delta))*r_k(+1)-r-pi(+1);

i-k=eta*q;

//Capital accumulation function
k=delta*i(-1)+(1-delta)*k(-1);


// Aggregate Labor Supply
w=c+phi*n;

//Intertemporal Euler Equation
c(+1)-sigma*(r-pi(+1))-theta_n*(n(+1)-n)+theta_tau*(t(+1)-t);

//The dynamics of inflation
pi=beta*pi(+1)-lambda_p*my_p;
//Markup
my_p_hat=y-n-w;
my_p_hat=y-k-r_k;


//Market clearing:
y=gamma_g*c+gamma_i*i+g;



//The production function where production is expressed as a funciton of capital and technology
y=(1-alpha)*n+alpha*k;

//Monetary policy rule
r=omega+phi_pi*pi(-1);


//Fiscal policy 
t=phi_b*b+phi_g*g;
b=(1+rho)*(b(-1)+g(-1)-y(-1));

//Fiscal policy shock
g=rho_g*g(-1)+e_g;

end;



initval;
c=0;
r=0;
n=0;
pi=0;
w=0;
e_g=0;
g=0;
i=0;
g=0;
k=0;
q=0;
r_k=0;
t=0;
my_p_hat=0;

end;

steady;

shocks;
var e_g=0.01^2;
end;

stoch_simul(periods=3000);


