
clc; clear all; close all

%% This code computes the steady state of a TANK model 
% calibration taken from Gali et al. (JEEA 2007)
% This version: September 5, 2021

%% Structural Parameters (quarterly calibration)
beta=0.99;                    % discount factor
eta=0.12;                     % share of fuel in consumption 
theta = 0.7;                  % intertemporal elasticity of substitution between oil and non oil goods
alpha_o=1/3;                  % elasticity of oil production wrt capital
alpha_no=1/3;                 % elasticity of non-oil production wrt capital
eps=10;                        % elasticity of substitution between differentiated goods
delta=0.025;                  % depreciation rate
gamma=1;                      % Inverse of intertemporal elast. of subst. (relative risk aversion)
varpi=0.2;                    % Intra-temporal elasticity of subs. of labor (inverse of Frisch elasticity)
varphi=0.5;                   % fraction of rule-of thumb
G=0.2;                        % public spending over GDP ratio
d=1;                          % public debt over GDP ratio
thetap=0.82;                  % NK baseline
mu=1;                         % indexation
eps2=1;                       % capacity utilization parameter 2
eps1=1/beta-(1-delta)*eps2;   % capacity utilization parameter 1
omega=0.02;
%% Steady State
Infl=1;                      % inflation targeting (agg)
YO=1;                        % oil production
YNO=1;                       % non-oil production
Y=YO+YNO;                    % production (aggregate)
L=1/3;                       % labor
IR_r=1/beta;                 % real interest rate
IR=Infl/beta;                % nominal interest rate
Lambdaq=1;                   % marginal value of investment (in terms of Lambda)  
Rk=1/beta-(1-delta);         % rental rate of capital
MCO=(eps-1)/eps;             % real marginal costs (oil)
MCNO=(eps-1)/eps;            % real marginal costs (non-oil)
KO=alpha_o*MCO*YO/Rk;        % capital (oil)
KNO=alpha_no*MCNO*YNO/Rk;    % capital (non-oil)
K=KO+KNO;                    % capital (agg)
WR=(1-alpha_o)*MCO*YO/L;     % wage of ricardian
WNR=(1-alpha_no)*MCNO*YNO/L; % wage of non-ricardian
I=delta*K;                   % investment (agg) 
C=Y-I-G;                     % consumption
Tau_NR=WNR*L-C;              % non ricardians taxes
D=4*d;                       % public debt
Tau_R=(G+(1/beta-1)*D-varphi*Tau_NR)/(1-varphi); % ricardans taxes
Lambda=C^(-gamma);           % marginal utlity of consumption
AO=YO/(KO^(alpha_o)*L^(1-alpha_o)); % production/productivity function (oil)
ANO=YNO/(KNO^(alpha_no)*L^(1-alpha_no)); % production/productivity function (non-oil)
M=1;                          % monetary policy shock
psi=WNR/(L^(varpi)*C^(gamma)); % disutility of labor supply
%% Steady-state values
Gss=G;
Mss=M;
AOss=AO;
ANOss=ANO;
Inflss=1;
Infl_NOss=1;
IRss=IR;
Tau_Rss=Tau_R;
Tau_NRss=Tau_NR;
Dss=D;
POstarss=1;
%% Parameters not affecting the steady state
rho_Infl=1.5;             % monetary polcy response on policy rate (inflation)
rho_Infl_O=1.5;           % monetary polcy response on policy rate (oil inflation)
rho_Infl_s=1.5;          % monetary polcy response on policy rate (subsidized inflation)
rho_y=0.0;                % monetary polcy response on output gap
chi=2.48;                 % investment adjustment cost (as in CEE). If 0, Lambdaq is constant
rhoAO=0.9;                % tfp persistence (oil)
rhoANO=0.9;               % tfp persistence (non-oil)
rhoG=0.9;                 % public spending persistence
rhoM=0.9;                 % monetary policy inertia
phiG=0.1;                 % tax reaction to G
phiD=0.33;                % tax reaction to debt
% adjusment cost coefficient to have the same linear Phillips Curve of the Calvo framework 
%chip=(eps-1)*calvo/(Inflss^2*(1-calvo)*(1-beta*calvo)); 
chip=10;
rhoPOstar=0.9;
%% Save parameters
save par beta eps1 eps2 alpha_o alpha_no delta gamma varpi Gss thetap mu omega theta AOss ANOss Mss eta psi Inflss Infl_NOss IRss eps varphi...
        POstarss chip rhoPOstar rho_Infl rho_Infl_O rho_Infl_s rho_y chi rhoAO rhoANO rhoG rhoM phiG phiD Tau_Rss Tau_NRss Dss
     

