
%***************************************************************************
% DYNARE Model IV Loglinearised - Fixed labour                             * 
%                                                                          *
% This version has intertemporally optimising consumers                    *
%                                                                          *
%                                                                          *
%                                                                          *               
%***************************************************************************

%Comments 
%-----------------
%Labour fixed. Firms assumed to be owned abroad for now so profits excluded.
%Stochastic variables: REM, Pt, An, At.  
%15 endogenous variables, 16 equations - doesn't match up.  
%Prices in nontraded sector can be flexible or sticky (Calvo) - see comments 
%in 'model' section. 


%List of variables (all variables with 'hat' suffix are in log-deviations from steady state.) 
%--------------------------------------------------------------------------
%cnhat: consumption of non-traded goods; cthat: consumption of traded
%goods; chat: consumption index; pnhat: price of nontradable goods; 
%phat: price index; ynhat: production of nontraded goods; ythat: production of traded goods;
%what: nominal wage; lnhat: labour employed in NT sector; lthat: labour
%employed in T sector; PiN: inflation in NT prices (pnhat-pnhat(-1)); 
%REM: level of remittances sent from abroad; REMhat log-deviation of REM;
%At/An: productivity in T/NT sector; Pt: price of tradable good (given exogenously)


%-----------------------------------------------------
% 0. Housekeeping (close graphics windows)
%-----------------------------------------------------

close all;

%-----------------------------------------------------
% 1. Define variables
% Endogenous (var) and exogenous (varexo)
%-----------------------------------------------------

var

cnhat, cthat, chat,
pnhat, phat, 
ynhat, ythat,
what, lnhat, lthat, PiN, 
REM, At, An, Pt;

varexo 

epsAt, epsAn, epsPt, epsREM ;



%-----------------------------------------------------
% 2. Define parameters and assign parameter values 
%-----------------------------------------------------

parameters

gamma, alphat, epsilon, Lbar, Ltbar, betah, betan, 
rglob, rprem, rdom,
ar_rem, ar_Pt, rho, tau, zeta, 
lamda, q, REMbar, Ptbar, Atbar, Anbar;		                       


% Setting parameters----------- 

gamma = 0.50;			%T-NT elasticity of subn in consumption
alphat = 0.65; 			%Cobb-douglas parameter for T production
epsilon = 11;	 		%Price elasticity of demand for NT goods value from Gali 2001
Lbar = 1;			    %Fixed labour supply, normalised to 1
betan = 0.99;           %Nontradable firms' discount factor
q = 0.6;                %Calvo probability price stays the same in following period. 
rglob = 0.05;           %World interest rate
rprem = 0.03;           %Risk premium
rdom = rglob+rprem;     %Domestic interest rate (assumed fixed exchange rate)
                        
Ltbar = 0.514478;        %Value from "Model2_FixL_allpam_noprof" (same model in levels)
betah = 1/(1+rdom);      %Household's discount factor

REMbar = 0.124;         %Steady state value (from "Model2..."
Wbar = 0.820226;        %Steady state value (from "Model2..."
psi = REMbar/(REMbar+Wbar); 
lamda = Ltbar/Lbar;  
Ptbar = 1;
Atbar = 0;
Anbar = 0;

ar_rem = 0.95; 				 
ar_Pt = 0.95; 			
rho = 0.95;			    %Autocorrelation of productivity shock
tau = 0.0; 			    %No crosscorrelation 
zeta = 0.0; 			%No conditional correlation of productivity shocks





%-----------------------------------------------------
% 3. Defining the model (Model IV in log deviations)
%-----------------------------------------------------
model(linear);

REM=ar_rem*REM(-1)+epsREM;
Pt=ar_Pt*Pt(-1)+epsPt;
An=rho*An(-1)+tau*At(-1)+epsAn;
At=rho*At(-1)+tau*An(-1)+epsAt;
#remhat=(REM-REMbar)/REMbar;
#pthat=(Pt-Ptbar)/Ptbar;
#expAn=exp(An);
#expAt=exp(At);
#expAnbar=exp(Anbar);
#expAtbar=exp(Atbar);
#expAnhat=(expAn-expAnbar)/expAnbar;
#expAthat=(expAt-expAtbar)/expAtbar;
chat=gamma*cthat+(1-gamma)*cnhat;
phat=gamma*pthat+(1-gamma)*pnhat;
#ro=(1/betah)-1;
PiN = pnhat - pnhat(-1);
#Pi = phat - phat(-1);
chat=chat(+1)-(rdom-Pi(+1)-ro);
cnhat = chat + phat - pnhat; 
cthat = chat + phat - pthat;
ynhat = expAnhat + lnhat;
ythat = expAthat + alphat*lthat;
what = ythat + pthat - lthat; 
ynhat = cnhat;
lthat = -((1-lamda)/lamda)*lnhat;

pnhat = what - expAnhat;

end;


%Flexible vs sticky prices
%-------------------------
%For flexible prices the last equation should be: 
%pnhat = what - expAnhat;
%For sticky prices the last equation(s) should be:
%#bmc = (1-q)*(1-q*betan)/q;
%#mcnhat = what - expAnhat;
%#mchat = mcnhat - pnhat;
%PiN = betan*PiN(+1) + bmc*mchat;
%[Can't solve for either]


%Setting initial values for numerical analysis	

initval;

epsREM=0.0062;
epsAt=0;
epsAn=0;
epsPt=0;
Pt=1;
An=0;
At=0;
REM=0.124;
end;


%-----------------------------------------------------
% 4. Calibration of Shocks
%-----------------------------------------------------

shocks;

var epsREM=0.009^2;
var epsAt=0.009^2;
var epsAn=0.009^2;
var epsAn,epsAt=zeta*0.009*0.009;
end;

	

%-----------------------------------------------------
% 5. Simulation
%-----------------------------------------------------

%check;
stoch_simul(periods=1000, irf=100);


% END OF PROGRAM