%% In The Name of God %% code for galadriel_version1 %% Mehran Mahmoudi %% DECLARE ENDOGENOUS VARIABLES var y pi m_s d_s w l c c_g m r inv q z R y_no x_e y_d a k l_y k_g p_e mc pi_d thetta y_o x_o l_o a_o i_x A_ix p_xstr p_ostr p_str y_ox y_x y_str ef dc fr es h A_I i_g d_f c_d c_n c_nf c_ns c_gd c_gn i_gd i_gn N pi_str vartheta s_f s_s mg trg zeta pi_e pi_o pi_cn p_cgn p_cn p_cnf p_cns p_ign p_d p_cgd p_id p_igd pi_cg pi_ig nu gy_no gy gy_o gi gi_g gc_g; predetermined_variables x_o; %% DECLARE EXOGENOUS SHOCKS varexo e_pistr e_ystr e_pio e_z e_theta e_a e_o e_A e_cg e_h e_mg e_d e_trg e_ix; %% DECLARE PARAMETERS parameters etta siggma gama b_m betta epsil delta R_bar varrho alpha varkappa gamma_y theta_y yno_yd xe_yd psi Gamma_mc Pe_mc taau xi gamma_o xo_yo theta_o lo_yo gamma_ix b_ig b_i ig_ix phi_o i_ix ix_xo P_oxbar ly_l lo_l xe_yo yox_yo theta_x dc_m effr_m esfr_m delta_g phi0 phi1 phi2 phi3 phi4 phi5 phi6 phi7 phi8 phi9 phi10 phi11 r_bar es_bar b_s cd_y cnf_y cns_y id_y in_y cgd_y cgn_y igd_y ign_y yo_y yx_y N_y cnf_N cns_N cgn_N in_N ign_N cd_yno cgd_yno id_yno igd_yno yx_yno theta_c theta_cn theta_cg theta_i theta_ig postr_yxo_ffr hbar omega_h ss_sf cnf_ffr in_ffr cgn_ffr ign_ffr yx_sfr ms_sfr cns_sfr rho_mg omega_pi omega_y rho_d varpi_pi varpi_y varpi_e tau_e P_d_bar a_c a_cn P_cn_bar P_cnf_bar P_cns_bar a_i P_id_bar P_in_bar a_cg P_cgd_bar P_cgn_bar a_ig P_igd_bar P_ign_bar rho_z rho_theta rho_a rho_o rho_A rho_ix rho_cg rho_nu rho_vartheta rho_zeta rho_trg rho_pistr rho_ystr rho_pio //kappa_pi kappa_s pi_bar pi_strbar; etta =2.89; siggma =1.1969; gama =0.1910; b_m =1.0959; r_bar =0.08;%% pi_bar =2.353489361863173;%% betta =0.9692; epsil =0.0179; delta =0.0139;%% R_bar =0.0469;%% pi_strbar =1;%% varrho =0.4058;%% gamma_y =0.77; theta_y =0.4919; yno_yd =0.77; xe_yd =0.23; alpha =0.6025; varkappa =4.7892; psi =0.0844; taau =0.6576; xi =0.7558; Gamma_mc =0.9; Pe_mc =0.1; gamma_o =0.7; theta_o =0.3027; xo_yo =73; lo_yo =0.27; xe_yo =0.1; yox_yo =0.9; ix_xo =5.8205; ig_ix =0.8; P_oxbar =6; i_ix =0.2; gamma_ix =0.8; b_ig =0.05; b_i =0.01; phi_o =1; ly_l =0.77; lo_l =0.23; theta_x =2.9; dc_m =0.2; effr_m =0.9; esfr_m =0.1; delta_g =0.0218; phi0 =0; phi1 =0.25/3; phi2 =0.25/3; phi3 =0.25/3; phi4 =0.75/8; phi5 =0.75/8; phi6 =0.75/8; phi7 =0.75/8; phi8 =0.75/8; phi9 =0.75/8; phi10 =0.75/8; phi11 =0.75/8; yx_sfr =0.6; ms_sfr =0.8; cns_sfr =0.6; es_bar =0.82; b_s =1.3414; cd_y =0.41; cnf_y =0.08; cns_y =0.03; id_y =0.217; in_y =0.046; cgd_y =0.095; cgn_y =0.025; igd_y =0.105; ign_y =0.028; yo_y =0.09; yx_y =0.03; N_y =0.11; cnf_N =0.5385; cns_N =0.1282; cgn_N =0.1538; in_N =0.22; ign_N =0.1795; cd_yno =0.46; cgd_yno =0.11; id_yno =0.20; igd_yno =0.11; yx_yno =0.12; theta_c =2.9039; theta_cn =3.9; theta_cg =5.5011; theta_i =1.2689; theta_ig =1.4661; postr_yxo_ffr=0.51; omega_h =10; ss_sf =1.46; hbar =(ss_sf/(1+omega_h*ss_sf)); cnf_ffr =0.6563; in_ffr =0.1719; cgn_ffr =0.11; ign_ffr =0.1719; rho_mg =0.3594; omega_pi =-1.5; omega_y =-1.5; rho_d =0.7; varpi_pi =-0.4; varpi_y =-0.8; varpi_e =-1.5; tau_e =0.6; P_d_bar =0.949029; a_c =0.6; a_cn =0.605; P_cn_bar =1.628159; P_cnf_bar =1.5; P_cns_bar =1.5; a_i =0.7879; P_id_bar =1.123384262; P_in_bar =2.154491; a_cg =0.3680; P_cgd_bar =0.8884; P_cgn_bar =1.745245; a_ig =0.8702; P_igd_bar =1.029938; P_ign_bar =2.032208; rho_z =0.7301; rho_theta =0.7885; rho_a =0.7609; rho_o =0.2531; rho_A =0.8607; rho_ix =0.7861; rho_cg =0.2249; rho_nu =0.6256; rho_vartheta =0.4787; rho_zeta =0.3247; rho_trg =0.9562; rho_pistr =0.2756; rho_ystr =0.2756; rho_pio =0.2618; kappa_pi =0.6; kappa_s =0.4; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MODEL EQUATIONS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% model(linear); %% demand for labor w = etta*l+siggma*c+gama*(siggma-1)*c_g; %% demand for real balances m = -(1/(1+r_bar)*b_m)*r+(1/b_m)*(siggma*c+gama*(siggma-1)*c_g); %% demand for foreign currency -b_s*m_s = (pi_strbar/(pi_strbar-betta)+b_s-1)*es-(betta/(pi_strbar-betta))*(es(+1)+pi(+1)-pi_str(+1)-(r_bar/(1+r_bar))*r) -(siggma*c+gama*(siggma-1)*c_g); %% Euler equation c = c(+1)-(1/siggma)*((r_bar/(1+r_bar))*r-pi(+1)-gama*(siggma-1)*(c_g(+1)-c_g)); %% household's investment decision Eq inv = (1/((1+betta)*epsil))*q+(1/(1+betta))*inv(-1)+(betta/(1+betta))*inv(+1) +(1/((1+betta)*epsil))*z; %% price of capital dynamics q = (1-delta)*betta*q(+1)+pi(+1)-(r_bar/(1+r_bar))*r+((1-betta*(1-delta))/R_bar)*R(+1); %%production function (non-oil GDP) y_no = a+alpha*k(-1)+alpha*varkappa*R+alpha*psi*k_g(-1)+(1-alpha)*l_y; %% total production (1/(1+varrho))*y_d = gamma_y^(1/theta_y)*yno_yd^((theta_y-1)/theta_y)*y_no +(1-gamma_y)^(1/theta_y)*xe_yd^((theta_y-1)/theta_y)*x_e; %% demand for labor w = -l_y+k(-1)+(1+varkappa)*R; %% demand for energy x_e = theta_y*(w+l_y-p_e)+(1-theta_y)*y_no; %% marginal costs mc = (gamma_y^theta_y)*Gamma_mc^(1-theta_y)*(alpha*R+(1-alpha)*w-alpha*psi*k_g(-1)-a) +((1-gamma_y)^theta_y)*(Pe_mc^(1-theta_y))*p_e; %% the law of motion for private capital k = (1-delta)*k(-1)+delta*(inv+z); %% NKPC pi_d = (betta/(1+betta*taau))*pi_d(+1)+(taau/(1+betta*taau))*pi_d(-1)+ (((1-betta*xi)*(1-xi))/((1+betta*taau)*xi))*(mc+thetta); %% oil production y_o = gamma_o*xo_yo^(1-theta_o)*x_o+(1-gamma_o)*lo_yo^(1-theta_o)*l_o+a_o; %% oil reserves accumulation x_o(+1) = (1+1/xo_yo-ix_xo)*x_o+ix_xo*i_x-(1/xo_yo)*y_o; %% investment in oil reserves production i_x = gamma_ix*i_g+(1-gamma_ix)*inv+A_ix; %% oil reserves price setting p_xstr = ((1-P_oxbar)*gamma_o*theta_o*xo_yo^(-theta_o)+ix_xo*(1+ix_xo*phi_o))*x_o(+1) +gamma_o*xo_yo^(-theta_o)*P_oxbar*p_ostr-(1-P_oxbar)*gamma_o*theta_o*xo_yo^(-theta_o)*y_o(+1) +(1+xo_yo^(-1)-ix_xo-gamma_o*xo_yo^(-theta_o))*p_xstr(+1)-ix_xo^2*phi_o*i_x(+1); %% demand for labor in oil sector l_o = y_o+theta_o^(-1)*((P_oxbar/(P_oxbar-1))*p_ostr-(1/(P_oxbar-1))*p_xstr+p_str-w); %% labor market clearing condition l = ly_l*l_y+lo_l*l_o; %% oil market clearing condition y_o = xe_yo*x_e+yox_yo*y_ox; %% nonoil export y_x = y_str-theta_x*(p_d-p_str); %% central bank balance sheet m = dc_m*dc+effr_m*(ef+fr)-esfr_m*(es+h+fr); %% the law of motion for public capital k_g = (1-delta_g)*k_g(-1)+delta_g*A_I; %% public investment implementation i_g = phi0*A_I+phi1*A_I(-1)+phi2*A_I(-2)+phi3*A_I(-3)+phi4*A_I(-4)+phi5*A_I(-5) +phi6*A_I(-6)+phi7*A_I(-7)+phi8*A_I(-8)+phi9*A_I(-9)+phi10*A_I(-10) +phi11*A_I(-11); %% market clearing condition y = cd_y*c_d+cnf_y*c_nf+cns_y*c_ns+id_y*inv+cgd_y*c_gd+cgn_y*c_gn+igd_y*i_gd+ign_y*i_gn +yo_y*y_o+yx_y*y_x-N_y*N; %% import N = cnf_N*c_nf+cns_N*c_ns+cgn_N*c_gn+ign_N*i_gn; %% domestic goods market clearing condition y_no = cd_yno*c_d+id_yno*inv+cgd_yno*c_gd+igd_yno*i_gd+yx_yno*y_x; %% evolution of the foreign reserves fr-(hbar/(1-hbar))*h = fr(-1)-(hbar/(1-hbar))*h(-1)-pi_str+postr_yxo_ffr*(p_ostr+y_ox) -(cnf_ffr*c_nf+cgn_ffr*c_gn+ign_ffr*i_gn); %% foreign exchange spot market equilibrium h+fr-(h(-1)+fr(-1)-pi_str)+yx_sfr*y_x = ms_sfr*(m_s-m_s(-1)-pi_str)+cns_sfr*c_ns; %% foreign exchange policy in spot market h = ((1+omega_h*ss_sf)^(-1))*(s_s-s_f+nu); %% monetary growth definition mg = m-m(-1)+pi; %% monetray policy mg = rho_mg*mg(-1)+omega_pi*(pi-trg)+omega_y*y+vartheta; %% exchange rate policy d_f = rho_d*d_f(-1)+varpi_pi*(pi-trg)+varpi_y*y+varpi_e*(kappa_s*ef+(1-kappa_s)*(ef-ef(-1)))+zeta; %% demand for imported private consumption c_n = c-theta_c*p_cn; %% demand for imported private consumption goods with official exchange rate c_nf = c_n-theta_cn*p_cnf; %% demand for imported private consumption goods with spot exchange rate c_ns = c_n-theta_cn*p_cns; %% demand for imported government investment %%i_n = i-theta_i*p_in; %% demand for imported government consumption c_gn = c_g-theta_cg*p_cgn; %% demand for imported private investment i_gn = i_g-theta_ig*p_ign; %% demand for domestic private consumption c_d = c-theta_c*p_d; %% demand for domestic government consumption c_gd = c_g-theta_cg*p_cgd; %% demand for domestic government investment %%i_d = i-theta_i*p_id; %% demand for domestic private investment i_gd = i_g-theta_ig*p_igd; %% the ratio of domestic prices to consumer prices p_d = pi_d-pi+p_d(-1); %% domestic energy price inflation pi_e = tau_e*(d_f+pi_o); %% official exchange rate depreciation d_f = s_f-s_f(-1); %% spot exchange rate depreciation d_s = s_s-s_s(-1); %% the ratio of energy prices to consumer prices p_e = pi_e-pi+p_e(-1); %% the ratio of total consumption import prices to consumer prices p_cn = pi_cn-pi+p_cn(-1); %% the ratio of official consumption import prices to total consumption import prices p_cnf = pi_str+d_f-pi_cn+p_cnf(-1); %% the ratio of spot consumption import prices to total consumption import prices p_cns = pi_str+d_s-pi_cn+p_cns(-1); %% the ratio of private investment prices to consumer prices %%p_i = pi_i-pi+p_i(-1); %% the ratio of domestic prices to private investment prices p_id = pi_d-pi+p_id(-1); %% the ratio of import prices to private investment prices %%p_in = d_f+pi_str-pi_i+p_in(-1); %% RER ef = d_f+pi_str-pi+ef(-1); %% RER based on spot exchange rate es = d_s+pi_str-pi+es(-1); %% the ratio of domestic prices to foreign prices p_str = pi_str-pi+p_str(-1); %% external term of trade p_ostr = pi_o-pi_str+p_ostr(-1); %% the ratio of domestic prices to government consumption prices p_cgd = pi_d-pi_cg+p_cgd(-1); %% the ratio of import prices to government consumption prices p_cgn = d_f+pi_str-pi_cg+p_cgn(-1); %% the ratio of domestic prices to government investment prices p_igd = pi_d-pi_ig+p_igd(-1); %% the ratio of import prices to government investment prices p_ign = d_f+pi_str-pi_ig+p_ign(-1); %% CPI inflation pi = (a_c)*pi_d+(1-a_c)*pi_cn; %% imported consumer price infation pi_cn = (a_cn)*(pi_str+d_f)+(1-a_cn)*(pi_str+d_s); %% private investment price inflation %%pi_i = (a_i)*pi_d+(1-a_i)*(d_f+pi_str); %% government consumption price inflation pi_cg = (a_cg)*pi_d+(1-a_cg)*(d_f+pi_str); %% government investment price inflation pi_ig = (a_ig)*pi_d+(1-a_ig)*(d_f+pi_str); %% investment-specific technology shock z = rho_z*z(-1)+e_z; %% mark-up shock thetta = rho_theta*thetta(-1)+0.5*e_pio+0.5*e_o+e_theta; %% productivity shock a = rho_a*a(-1)+e_a; %% productivity shock to oil production function a_o = rho_o*a_o(-1)-0.1*pi_o(-1)+e_o; %% the budget authorized for government investment A_I = rho_A*A_I(-1)+0.85*e_pio+0.85*e_o+e_A; %% the oil reserves investment shock A_ix = rho_ix*A_ix(-1)+0.85*pi_o(-1)+0.85*a_o(-1)+e_ix; %% fiscal policy c_g = rho_cg*c_g(-1)+0.85*y_o+0.85*pi_o(-1)+e_cg; %% foreign exchange spot market policy shock nu = rho_nu*nu(-1)+0.15*pi_o(-1)+0.5*a_o(-1)-0.5*zeta(-1)+e_h; %% monetary growth rate shock vartheta = rho_vartheta*vartheta(-1)-0.25*pi_o(-1)-0.25*a_o(-1)+e_mg; %% exchange rate shock zeta = rho_zeta*zeta(-1)-0.5*pi_o(-1)-0.85*y_o-0.5*nu(-1)+e_d; %% time-varying inflation target trg = rho_trg*trg(-1)+e_trg; %% foreign price inflation pi_str = rho_pistr*pi_str(-1)+e_pistr; %% foreign income y_str = rho_ystr*y_str(-1)+0.2*pi_o(-1)+e_ystr; %% oil price inflation pi_o = rho_pio*pi_o(-1)-0.1*a_o+0.2*y_str(-1)+e_pio; gy_no = y_no-y_no(-1); gy = y-y(-1); gy_o = y_o-y_o(-1); gi = inv-inv(-1); gi_g=i_g-i_g(-1); gc_g=c_g-c_g(-1); end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STEADY STATES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% initval; y=0; pi=0; d_s=0; w=0; l=0; c=0; c_g=0; m=0; r=0; inv=0; q=0; z=0; R=0; y_no=0; x_e=0; y_d=0; a=0; k=0; l_y=0; k_g=0; p_e=0; mc=0; thetta=0; y_o=0; x_o=0; l_o=0; a_o=0; i_x=0; A_ix=0; p_xstr=0; p_ostr=0; p_str=0; y_ox=0; ef=0; dc=0; fr=0; es=0; h=0; A_I=0; i_g=0; d_f=0; c_d=0; c_nf=0; c_ns=0; c_gd=0; c_gn=0; i_gd=0; i_gn=0; N=0; pi_str=0; vartheta=0; mg=0; trg=0; zeta=0; pi_e=0; pi_o=0; p_cgn=0; p_ign=0; p_d=0; p_cgd=0; p_id=0; p_igd=0; pi_cg=0; pi_ig=0; nu=0; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STABILITY CONDITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% model_diagnostics; %%resid(1); steady; check; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EXOGENEOUS SHOCKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% shocks; var e_pistr; stderr 0.0098; var e_ystr; stderr 0.0047; var e_pio; stderr 0.02266; var e_z; stderr 0.03830; var e_theta; stderr 0.0828; var e_a; stderr 0.06498; var e_o; stderr 0.01894; var e_A; stderr 0.07394; var e_cg; stderr 0.01132; var e_h; stderr 0.07009; var e_mg; stderr 0.01371; var e_d; stderr 0.01; //var e_trg; stderr 0.01; //var e_ix; stderr 0.01; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SIMULATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% stoch_simul(periods=200120,drop=10000, irf=50, graph_format=(pdf), nograph) gy_no y_o gy pi pi_d d_f d_s h;