%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% firms
Param.z_ss=1;                   % normalization
Param.eps_p=7;                  % elasticity of substitution within sectors
Param.eps_s=3;                  % elasticity of substitution across sectors (should be less than eps_p, for smaller values the sum of square residuals is quite large)
Param.theta=0.2;                % price rigidity
Param.gamma=0.615;              % high-skill sector input share 

% government
Param.psi=2;                    % Taylor rule coefficient on inflation

% labor market

Param.chi_bar_H=1;            % disutility weight for labor H
Param.chi_bar_L=1;            % disutility weight for labor L
Param.alpham_H=0.1875;          % matching efficiency
Param.alpham_L=0.2297;          % matching efficiency
Param.alpha=0.5;                % matching elasticity
Param.vartheta=0.5;             % bargaining power
Param.iota=1;  
Param.eta =1;  

Param.mu=0.8;                   
Param.rho_H_ss=0.984;     %0.984     % retention - high skill
Param.rho_L_ss=0.967;       % 0.967       % retention - low skill

Param.fs_H_ss=0.1718;                    % high-skill job finding rate
Param.fs_L_ss=0.1608;                    % low-skill job finding rate

Param.w_L=2;                             % min wage in low sector is set exogeneously
% shocks charachteristics

Param.sigma_z=0.0031;
Param.rho_z=0.9752;

Param.rho_rh=0.8437;
Param.sigma_rh=0.0008;

Param.rho_rl=0.3389;
Param.sigma_rl=0.0028;

Param.rho_b=0.9448;
Param.sigma_b=0.0038;

Param.rho_i=0.8527; 
Param.sigma_i=0.0013;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Targets
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%Targets.lss=0.645;              % labor participation rate
Targets.l_H=0.6063;              % H-skill labor participation rate
Targets.l_L=0.0387;              % L-skill labor participation rate
Targets.intrate=0.003;           % interest rate
Targets.Cratio=0.72;             % U/E consumption ratio
Targets.B_Hconst=0.07;             % B constant - hiring costs 
Targets.B_Lconst=0.07;             % B constant - hiring costs 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% solve for targeted SS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%starting values, mostly arbitrary

c_eH_ss=0.93;
c_eL_ss=0.8;
c_u_ss=0.6;
c_n_ss=0.4;
l_ss=0.645;
u_ss=0.06;
e_ss=0.59;
e_H_ss=0.5546;
e_L_ss=0.0354;
l_H_ss=0.6063;
l_L_ss=0.0434;
u_H_ss=0.0517;
u_L_ss=0.008;
s_H_ss=0.08;
s_L_ss=0.07;
v_H_ss=0.095;
v_L_ss=0.14;
fv_H_ss=0.2;
fv_L_ss=0.32; 
k_H_ss=0.6;
k_L_ss=0.2;
x_ss=0.36;
b_bar_ss=0.4;
beta=0.997;
i_bar=0.002;
tau_ss=0.2;
w_H_ss=9;
q_H_ss=4;
q_L_ss=3;
dw_H_ss=0.;
dw_L_ss=0.;
d_H_ss=4;
d_L_ss=1;
D_ss=4;
OmegaH_ss=0.1;
OmegaL_ss=0.05;
GammaH_ss=0.4;
GammaL_ss=0.2;
xi_bar_H=1;
xi_bar_L=1;
PstarH_P_ss=1.7;
PstarL_P_ss=1.36;
B_H=0.8;
B_L=0.42;
Y_ss=0.8;
Y_H_ss=0.6;
Y_L_ss=0.2;
tau_u_ss=2;
p_aH_ss=10;
p_bH_ss=6;
varpsi_H_ss=3.9;
p_aL_ss=6.8;
p_bL_ss=5;
varpsi_L_ss=2;
pi=1;
PH_P_ss=1.7;
PL_P_ss=1.36;

xstartT=[c_eH_ss c_eL_ss c_u_ss c_n_ss l_ss u_ss e_ss e_H_ss e_L_ss l_H_ss l_L_ss u_H_ss u_L_ss s_H_ss s_L_ss v_H_ss v_L_ss fv_H_ss fv_L_ss k_H_ss k_L_ss x_ss b_bar_ss beta i_bar tau_ss w_H_ss q_H_ss q_L_ss dw_H_ss dw_L_ss d_H_ss d_L_ss D_ss ...
         OmegaH_ss OmegaL_ss GammaH_ss GammaL_ss xi_bar_H xi_bar_L PstarH_P_ss PstarL_P_ss B_H B_L Y_ss Y_H_ss Y_L_ss tau_u_ss p_aH_ss p_bH_ss varpsi_H_ss p_aL_ss p_bL_ss varpsi_L_ss pi PH_P_ss PL_P_ss];

[ system0T ] =MinWageModelSS_Targets_Final( xstartT, Param,Targets);

options = optimoptions('fsolve','Display','final','MaxFunEvals',30000,'MaxIter',10000);
xx2TN=fsolve('MinWageModelSS_Targets_Final',xstartT,options,Param,Targets)';

xx2T=real(xx2TN);
[ system2T ] = MinWageModelSS_Targets_Final( xx2T, Param,Targets);

% save the parameters that depend on the targets
Param.b_bar_ss=xx2T(23);                    % borrowing limit - consumption ratio
Param.beta=xx2T(24);                        % discount factor - interest rate
Param.xi_bar_H=xx2T(39);                    % utility from home production H
Param.xi_bar_L=xx2T(40);                    % utility from home production L
Param.B_H=xx2T(43);                         % vacancy cost H
Param.B_L=xx2T(44);                         % vacancy cost L

% get the steady state values
            
c_eH_ss=xx2T(1);
c_eL_ss=xx2T(2);
c_u_ss =xx2T(3);
c_n_ss =xx2T(4);
l_ss=xx2T(5);
u_ss=xx2T(6);
e_ss=xx2T(7);
e_H_ss=xx2T(8);
e_L_ss=xx2T(9);
l_H_ss=xx2T(10);
l_L_ss=xx2T(11);
u_H_ss=xx2T(12);
u_L_ss=xx2T(13);
s_H_ss=xx2T(14);
s_L_ss=xx2T(15);
v_H_ss=xx2T(16);
v_L_ss=xx2T(17);
fv_H_ss=xx2T(18);
fv_L_ss=xx2T(19);
k_H_ss=xx2T(20);
k_L_ss=xx2T(21);
x_ss=xx2T(22);
tau_ss=xx2T(26);
w_H_ss=xx2T(27);
q_H_ss=xx2T(28);
q_L_ss=xx2T(29);
dw_H_ss=xx2T(30);
dw_L_ss=xx2T(31);
d_H_ss=xx2T(32);
d_L_ss=xx2T(33);
D_ss=xx2T(34);
OmegaH_ss=xx2T(35);
OmegaL_ss=xx2T(36);
GammaH_ss=xx2T(37);
GammaL_ss=xx2T(38);
PstarH_P_ss=xx2T(41);
PstarL_P_ss=xx2T(42);
Y_ss=xx2T(45);
Y_H_ss=xx2T(46);
Y_L_ss=xx2T(47);
tau_u_ss=xx2T(48);
p_aH_ss=xx2T(49);
p_bH_ss=xx2T(50);
varpsi_H_ss=xx2T(51);
p_aL_ss=xx2T(52);
p_bL_ss=xx2T(53);
varpsi_L_ss=xx2T(54);
PH_P_ss=xx2T(56);
PL_P_ss=xx2T(57);
w_L=Param.w_L;
fs_H_ss=Param.fs_H_ss;                   
fs_L_ss=Param.fs_L_ss; 

save vecSS l_ss e_H_ss e_L_ss u_H_ss u_L_ss u_ss e_ss l_H_ss l_L_ss s_H_ss s_L_ss k_H_ss k_L_ss v_H_ss v_L_ss ...
                  x_ss c_eH_ss c_eL_ss c_u_ss c_n_ss OmegaH_ss OmegaL_ss GammaL_ss GammaH_ss  w_H_ss w_L tau_u_ss tau_ss...
                  fs_H_ss fs_L_ss fv_H_ss fv_L_ss PstarH_P_ss PstarL_P_ss PH_P_ss PL_P_ss p_aH_ss p_bH_ss varpsi_H_ss p_aL_ss p_bL_ss varpsi_L_ss q_H_ss q_L_ss Y_ss Y_H_ss Y_L_ss D_ss d_H_ss d_L_ss dw_H_ss dw_L_ss 
          
           
% save parameters in the .mat file as well

beta=xx2T(24);
alpham_H=Param.alpham_H;         
alpham_L=Param.alpham_L;  
alpha=Param.alpha;                
vartheta=Param.vartheta;  
chi_bar_H=Param.chi_bar_H;
chi_bar_L=Param.chi_bar_L;
xi_bar_H=xx2T(39);                    
xi_bar_L=xx2T(40); 
iota=Param.iota;
eta =Param.eta;  
eps_p=Param.eps_p;                  
eps_s=Param.eps_s;  
theta=Param.theta;            
gamma=Param.gamma;
psi=Param.psi;    
mu=Param.mu; 
rho_H_ss=Param.rho_H_ss;              
rho_L_ss=Param.rho_L_ss; 
z_ss=Param.z_ss; 
i_bar=xx2T(25);
B_H=xx2T(43);                         
B_L=xx2T(44);  
b_bar_ss=xx2T(23);
 
rho_z=Param.rho_z;
sigma_z=Param.sigma_z;
rho_rh=Param.rho_rh;
sigma_rh=Param.sigma_rh;
rho_rl=Param.rho_rl;
sigma_rl=Param.sigma_rl;
rho_b=Param.rho_b;
sigma_b=Param.sigma_b;
rho_i=Param.rho_i; 
sigma_i=Param.sigma_i;

save param beta alpham_H alpham_L alpha vartheta chi_bar_H chi_bar_L xi_bar_H xi_bar_L iota eta eps_p eps_s theta ...
                   gamma psi mu rho_H_ss rho_L_ss z_ss i_bar B_H B_L b_bar_ss rho_z sigma_z rho_rh sigma_rh rho_rl sigma_rl rho_b sigma_b rho_i sigma_i
          
dynare MinWageModel 



 