% global phi epsilon gamma z_f  z_g z_in beta alpha_f alpha_i alpha_g lambda_c lambda_g  lambda_p  chi_f chi_i Phi_f Phi_in delta eta w_g chi_g tau M_0
% 
% phi=0.4 ;% Degree of formalisation
% epsilon= 4 ;%CES parameter
% gamma=0.4; % Share of formal output in total final output
% z_f= 1; % Productivity parameter of formal output
% z_g= 1; %  Productivity parameter of public sector output
% z_in=0.5; %  Productivity parameter of informal sector output
% beta= 0.99; % subjective discount factor
% alpha_f=0.45; %Labor share in formal sector 
% alpha_i= 0.65; % Labor share in informal sector
% alpha_g= 0.55;  %Labor share in public sector
% lambda_c=0.6;  % Prob. of losing a casual job
% lambda_g= 0.1;  % Prob. of losing a public sector job
% lambda_p= 0.4;  % Prob. of losing a private sector job
% chi_f=0.71;   % Cost of vacancy in formal
% chi_i= 0.5;  % Cost of vacancy in finormal
% chi_g= 0.6;
% Phi_f=0.75;   % Bargaining parameter for formal sector
% Phi_in =0.25;  %  Bargaining parameter for informal sector
% delta=0.05;  % depreciaiton
% eta= 0.7;   % Matching parameter
% w_g= 1;  % wage in govt. sector
% tau= 0.3; 
% M_0= 0.5; 

function [ys] = STEADYB()
	
global M_

phi=0.4 ;% Degree of formalisation
epsilon= 4 ;%CES parameter
gamma=0.6; % Share of formal output in total final output
z_f= 1; % Productivity parameter of formal output
z_g= 1; %  Productivity parameter of public sector output
z_in=0.5; %  Productivity parameter of informal sector output
beta= 0.99; % subjective discount factor
alpha_f=0.65; %Labor share in formal sector 
alpha_i= 0.8; % Labor share in informal sector
alpha_g= 0.55;  %Labor share in public sector
lambda_c=0.6;  % Prob. of losing a casual job
lambda_g= 0.1;  % Prob. of losing a public sector job
lambda_p= 0.4;  % Prob. of losing a private sector job
chi_f=0.71;   % Cost of vacancy in formal
chi_i= 0.5;  % Cost of vacancy in finormal
chi_g= 0.6;
Phi_f=0.75;   % Bargaining parameter for formal sector
Phi_in =0.25;  %  Bargaining parameter for informal sector
delta=0.005;  % depreciaiton
eta= 0.7;   % Matching parameter
w_g= 1;  % wage in govt. sector
tau= 0.3; 
M_0= 0.85; 

%Equation 1
Rstar=1/beta; % interest rate on bonds

%Equation 2
rstar=(1/beta)+delta-1;   % interest rate on capital 

%Equation 3
% to find the ss of theta_f
functheta_f= @(theta_f) Phi_f + ((1-Phi_f)*(1-lambda_p)*beta*(M_0*theta_f)^(1-eta)*w_g)/(1-beta*(1-lambda_g)*(1-(M_0*theta_f)^(1-eta)))- (w_g*(1-beta*(1-lambda_p)*(1-(M_0*theta_f)^(1-eta))))/(1-beta*(1-lambda_g)*(1-(M_0*theta_f)^(1-eta)));
theta_f0=0.5;
thetaf = fsolve(functheta_f,theta_f0);
theta_fstar=thetaf;

%Equation 4
% to find wage in the private sector
w_pstar= (w_g*(1-beta*(1-lambda_p)*(1-(M_0*theta_fstar)^(1-eta))))/(1-beta*(1-lambda_g)*(1-(M_0*theta_fstar)^(1-eta)));

%Equation 5
%  labor in the govt. sector
l_gstar=((w_g)/(alpha_g*z_g))^(1/(alpha_g-1));

%Equation 6
%  labor share in formal sector
l_fstar=((M_0*theta_fstar)^(1-eta)-l_gstar*(lambda_g+(1-lambda_g)*(M_0*theta_fstar)^(1-eta)))/(lambda_p+(1-lambda_p)*(M_0*theta_fstar)^(1-eta));

%Equation 7
% formal output
y_fstar= z_f*((1-alpha_f)/alpha_f)*(w_pstar+(1-beta*(1-lambda_p))*((chi_f*z_f)/(M_0*theta_fstar)^(-eta)))^(1-alpha_f)*l_fstar*rstar^(alpha_f-1);


%Equation 8
%  mu_p (Lagrange multiplier for the private formal sector)

mu_pstar=1/(z_f*alpha_f^(alpha_f)*(1-alpha_f)^(1-alpha_f))*(w_pstar+(1-beta*(1-lambda_p))*(chi_f*z_f)/(M_0*theta_fstar)^(-eta))^(alpha_f)*(rstar^(1-alpha_f));

%Equation 9
% Vacancy in formal sector

v_pstar=(lambda_p)/M_0*theta_fstar^(-eta)*l_fstar ;

%Equation 10
%mu_f finder

mu_fstar=(chi_f*z_f)/(M_0*theta_fstar)^(-eta);

%Equation 11
% Price for formal sector

p_fstar=phi^(1/(1-epsilon))*(epsilon/(epsilon-1))*mu_fstar;

%Equation 12
% Capital stock

kstar=(1-alpha_f)*y_fstar*mu_fstar/rstar;

%Equation 13
% Formal unemmployment

u_fstar=(lambda_p*(1-l_gstar)+lambda_g*l_gstar)/(lambda_p+(1-lambda_p)*M_0*theta_fstar^(1-eta));

%Equation 14
%investment

istar=delta*kstar;


%syms a b c d e f g

%eq1=   a*(b/c)*(1-Phi_in)*(d)^(-eta)-chi_i*(1-beta*(1-lambda_c)+Phi_in*(1-lambda_c)*beta*(d)^(1-eta));

%eq2=   e-a*alpha_i*(b/c)+chi_i*(1-beta*(1-lambda_c))/(d)^(-eta);

%eq3=    f-(beta*(d)^(1-eta)*e)/(1-beta*(1-lambda_c)*(1-(d)^(1-eta)));

%eq4=    b-z_in*((1-alpha_i)/(alpha_i)*(e+(1-beta*(1-lambda_c))*chi_i*z_in)/(f)*(d)^(-eta))^(1-alpha_i)*(c);

%eq5=   c-((1-g)*(d)^(1-eta))/(lambda_c+(1-lambda_c)*(d)^(1-eta));

%eq6=    g-((1-alpha_i)*b*a)/f ;

%eq7=   a-1/(z_in*(alpha_i)^(alpha_i)*(1-alpha_i)^(1-alpha_i))*(e+(1-beta*(1-lambda_c))*chi_i*z_in/((d)^(1-eta)))^(alpha_i)*(f)^(1-alpha_i);

%result= vpasolve([eq1,eq2,eq3,eq4,eq5,eq6,eq7]);



%To find the variables in the informal sector which comes as a solution to
%the system of equations
% Equation 15
eq1= @(mu_in, y_in, l_c, theta_in)    mu_in*(y_in/l_c)*(1-Phi_in)*(M_0*theta_in)^(-eta)-(chi_i)*(1-beta*(1-lambda_c)+(Phi_in)*(1-lambda_c)*beta*(M_0*theta_in)^(1-eta));

% Equation 16
eq2= @(mu_in, y_in, l_c, theta_in, w_c)   w_c-mu_in*alpha_i*(y_in/l_c)+(chi_i)*(1-beta*(1-lambda_c))/(M_0*theta_in)^(-eta);

% Equation 17
eq3= @(theta_in, w_c, w_s)   w_s-(beta*(M_0*theta_in)^(1-eta)*w_c)/(1-beta*(1-lambda_c)*(1-(M_0*theta_in)^(1-eta)));

% Equation 18
eq4= @(y_in, l_c, theta_in, w_c, w_s)   y_in-((1-alpha_i)/(alpha_i)*(w_c+(1-beta*(1-lambda_c))*(chi_i*z_in)/(M_0*theta_in)^(-eta))/w_s)^(1-alpha_i)*l_c;
%(((1-alpha_i)/(alpha_i))*((w_c+(1-beta*(1-lambda_c))*(chi_i)*(z_in))/(theta_in)^(-eta))/(w_s))^(1-alpha_i)*(l_c);

% Equation 19
eq5= @( l_c, theta_in, l_s)    l_c-((1-l_s)*(M_0*theta_in)^(1-eta))/(lambda_c+(1-lambda_c)*(M_0*theta_in)^(1-eta));

% Equation 20
eq6= @(mu_in, y_in,w_s, l_s)   l_s-((1-alpha_i)*y_in*mu_in)/w_s ;

% Equation 21
eq7= @(mu_in,theta_in, w_c, w_s)  mu_in-1/((z_in)*(alpha_i)^(alpha_i)*(1-alpha_i)^(1-alpha_i))*(w_c+(1-beta*(1-lambda_c))*(chi_i)*(z_in)/((M_0*theta_in)^(1-eta)))^(alpha_i)*(w_s)^(1-alpha_i);

eq1_7= @(xv) [eq1(xv(1),xv(2),xv(3),xv(4)); eq2(xv(1),xv(2),xv(3),xv(4),xv(5)); eq3(xv(4),xv(5),xv(6)); eq4(xv(2),xv(3),xv(4),xv(5),xv(6)); eq5(xv(3),xv(4),xv(7)); eq6(xv(1),xv(2),xv(6),xv(7)); eq7(xv(1),xv(4),xv(5),xv(6))];

eq_soln = fsolve(eq1_7, [1.5;3;3;1.5;1.6;1.75;0.2]);

mu_instar=eq_soln(1,:);
y_instar =eq_soln(2,:);
l_cstar =eq_soln(3,:);
theta_instar=eq_soln(4,:);
w_cstar =eq_soln(5,:);
w_sstar=eq_soln(6,:);
l_sstar=eq_soln(7,:);
%syms mu_in y_in l_c theta_in w_c w_s l_s

%eq1=   mu_in*(y_in/l_c)*(1-Phi_in)*(theta_in)^(-eta)-chi_i*(1-beta*(1-lambda_c)+Phi_in*(1-lambda_c)*beta*(theta_in)^(1-eta));

%eq2=   w_c-mu_in*alpha_i*(y_in/l_c)+chi_i*(1-beta*(1-lambda_c))/(theta_in)^(-eta);

%eq3=    w_s-(beta*(theta_in)^(1-eta)*w_c)/(1-beta*(1-lambda_c)*(1-(theta_in)^(1-eta)));

%eq4=    y_in-z_in*(l_c)*((1-alpha_i)/(alpha_i)*(w_c+(1-beta(1-lambda_c))*chi_i*z_in)/(w_s)*(theta_in)^(-eta))^(1-alpha_i);

%eq5=   l_c-((1-l_s)*(theta_in)^(1-eta))/(lambda_c+(1-lambda_c)*(theta_in)^(1-eta));

%eq6=    l_s-((1-alpha_i)*y_in*mu_in)/w_s ;

%eq7=   mu_in-1/(z_in*(alpha_i)^(alpha_i)*(1-alpha_i)^(1-alpha_i))*(w_c+(1-beta*(1-lambda_c))*chi_i*z_in/((theta_in)^(1-eta)))^(alpha_i)*(w_s)^(1-alpha_i);

%result= vpasolve([eq1,eq2,eq3,eq4,eq5,eq6,eq7]);

% Equation 22
% price of informal sector
p_instar=(1-phi)^(1/(1-epsilon))*(epsilon/(epsilon-1))*mu_instar;  

% Equation 23
 %vacancy rate in casual sector
v_cstar= (lambda_c/(M_0*theta_instar)^(-eta))*l_cstar ;     

% Equation 24
mu_cstar= (chi_i*z_in)/(M_0*theta_instar)^(-eta);  

% Equation 25
%unemployment rate in informal
u_instar= (lambda_c*(1-l_sstar)/(lambda_c+(1-lambda_c)*(M_0*theta_instar)^(1-eta))) ; 

% Equation 26
%price levels
pstar= 1/(gamma^(gamma)*(1-gamma)^(1-gamma))*p_fstar^(gamma)*p_instar^(1-gamma) ;  

% Equation 27
% output level
ystar=y_fstar^(gamma)*y_instar^(1-gamma) ;  

% Equation 28
% vacancy rate for public sector
v_gstar=(lambda_g*l_gstar)/(M_0*theta_fstar)^(1-eta) ;

% Equation 29
 % consumption
cstar= ystar-istar-z_f*phi*(chi_g*v_gstar+chi_f*v_pstar)-chi_i*z_in*v_cstar*(1-phi) ; 

% Equation 30
% Lagrange multiplier
xi_cstar=1/cstar;

% Equation 31
xi_fstar=(w_pstar*(1-tau)*xi_cstar)/(1-beta*(1-lambda_p)*(1-(M_0*theta_fstar)^(1-eta)));  

% Equation 32
xi_instar=(w_cstar*xi_cstar)/(1-beta*(1-lambda_c)*(1-(M_0*theta_instar)^(1-eta)));

 %equation 35
 gstar=z_g*(l_gstar)^(alpha_g);
 
 %Equation 36
 ustar=1-chi_f*(l_fstar-l_gstar)-(1-chi_i)*(l_sstar-l_cstar);
 
 ys=[cstar; theta_instar; theta_fstar; pstar; Rstar; rstar ; w_pstar; w_cstar; w_sstar; p_fstar; p_instar;  ystar;  y_instar; y_fstar; l_fstar; l_gstar; l_cstar; l_sstar; kstar;mu_pstar; 
     mu_fstar;  mu_instar; mu_cstar; v_pstar; v_gstar; v_cstar; istar; xi_cstar; xi_fstar; xi_instar; gstar;ustar];
end

 %ys=[cstar; theta_instar; theta_fstar; pstar; Rstar; rstar ; w_pstar; w_cstar; w_sstar; p_fstar; p_instar;  ystar;  y_instar; y_fstar; l_pstar; l_gstar; l_cstar; l_sstar; kstar;mu_pstar; mu_fstar;  mu_instar; mu_cstar; v_pstar; v_gstar; v_cstar; istar; xi_cstar; xi_fstar; xi_instar; gstar;ustar];