
if DifFinalGoods==0
    O_G=O_Z;
    O_A=O_Z;	
    O_I=O_Z;	
    O_Co=O_Z;
    ETA_G=ETA_Z;
    ETA_A=ETA_Z;
    ETA_I=ETA_Z;
    ETA_Co=ETA_Z;
end

%1-10
pi_ss           = pibar;
piZ_ss          = pi_ss;
pitil_ss        = piZ_ss^ALPHA_PIz*pi_ss^(1-ALPHA_PIz);
R_ss            = a_ss^SIGMA*pi_ss/BETTA;
Rstar_ss        = a_ss^SIGMA*pi_ss/(BETTA*piS_ss*xi_ss);
pistar_ss       = pi_ss/piS_ss;
piFstar_ss      = pistar_ss;
fstar_ss        = (1/xistar_ss)^(1/GAMMA_star);
wedCo_ss        = 1;
wedH_ss         = 1;


%11-20
wtil_ss         = 1;
ptilH_ss        = 1;
ptilF_ss        = 1;
ptilHstar_ss	= 1;
DelW_ss         = wtil_ss^-EPSILON_W;
DelH_ss         = ptilH_ss^-EPSILON_H;
DelF_ss         = ptilF_ss^-EPSILON_F;
DelHstar_ss     = ptilHstar_ss^-EPSILON_Hstar;
mcW_ss          = (EPSILON_W-1)/EPSILON_W*wtil_ss;
mcH_ss          = (EPSILON_H-1)/EPSILON_H*ptilH_ss;


%21-30
mcF_ss          = (EPSILON_F-1)/EPSILON_F*ptilF_ss;
mcHstar_ss      = (EPSILON_Hstar-1)/EPSILON_Hstar*ptilHstar_ss;
gGamaW_ss       = a_ss*pi_ss;
gGamaH_ss       = pi_ss;
gGamaF_ss       = pi_ss;
gGamaHstar_ss	= pistar_ss;
KAPPA_O         = sCO_ss*pO_ss^(ETA_C-1);
if pH_ss==1 && pO_ss==1   
    pA_ss=1;
else
    pCA_implicit = @(pCA) (1-KAPPA_O-KAPPA_A)                               ... 
                    *(                                                      ...
                    (1-O_Z)*pH_ss^(1-ETA_Z)                                 ...
                    +O_Z*(                                                  ...
                          ((pCA*zA_ss)^(1-ETA_A)-(1-O_A)*pH_ss^(1-ETA_A))/O_A ...
                          )^((1-ETA_Z)/(1-ETA_A))                           ...
                     )^((1-ETA_C)/(1-ETA_Z))                                ...
                    +KAPPA_O*pO_ss^(1-ETA_C)                                ...
                    +KAPPA_A*pCA^(1-ETA_C)                                  ...
                    -1;  
    pA_ss       = fzero(pCA_implicit,1);
end
pF_ss           = ((pA_ss^(1-ETA_A)-(1-O_A)*(pH_ss)^(1-ETA_A))/O_A)^(1/(1-ETA_A));
pZ_ss           = ((1-O_Z)*pH_ss^(1-ETA_Z)+O_Z*pF_ss^(1-ETA_Z))^(1/(1-ETA_Z));


%31-40
pHtil_ss        = pH_ss*mcH_ss;
pMstar_ss       = xiMstar_ss^(1/GAMMA_Mstar)*fstar_ss;
rer_ss          = mcF_ss*pF_ss/pMstar_ss;
pHstar_ss       = pHtil_ss/rer_ss/mcHstar_ss;
pOstar_ss       = pO_ss/rer_ss*xiO_ss^(1/(RHO_O-1));
pCostar_ss      = pCo_ss/rer_ss;
xiCostar_ss     = (pCostar_ss/fstar_ss)^GAMMA_Costar;
xiOstar_ss      = (pOstar_ss/fstar_ss)^GAMMA_Ostar;
pG_ss           = ((1-O_G)*pH_ss^(1-ETA_G)+O_G*pF_ss^(1-ETA_G))^(1/(1-ETA_G));
pI_ss           = ((1-O_I)*pH_ss^(1-ETA_I)+O_I*pF_ss^(1-ETA_I))^(1/(1-ETA_I));


%41-50
pICo_ss         = ((1-O_Co)*pH_ss^(1-ETA_Co)+O_Co*pF_ss^(1-ETA_Co))^(1/(1-ETA_Co));
u_ss            = 1- log(pI_ss)/PHI_U;
q_ss            = pI_ss/varomega_ss;
rK_ss           = (q_ss*(a_ss^SIGMA/BETTA-1+DELTA)-pI_ss*TAU_K*DELTA)...
                  /(1-TAU_K)/(u_ss-pI_ss/PHI_U *(exp(PHI_U*(u_ss-1))-1));
phi_u_ss        = rK_ss/PHI_U*(exp(PHI_U*(u_ss-1))-1);
hd_ss           = h_ss/DelW_ss;
yZ_ss           = kS_ss^ALPHA*(a_ss*wedH_ss*hd_ss)^(1-ALPHA);
xZ_ss           = yZ_ss; 
yHtil_ss        = z_ss*((1-ALPHA_O)^(1/ETA_O)*xZ_ss^((ETA_O-1)/ETA_O)...
                        +ALPHA_O   ^(1/ETA_O)*xO_ss^((ETA_O-1)/ETA_O)...
                       )^(ETA_O/(ETA_O-1));
w_ss            = pHtil_ss*(1-ALPHA)*xZ_ss/hd_ss...
                  *((1-ALPHA_O)*yHtil_ss/(z_ss^(1-ETA_O)*xZ_ss))^(1/ETA_O);


%51-60
k_ss            = kS_ss*a_ss/u_ss;
i_ss            = k_ss*(1-(1-DELTA)/a_ss)/varomega_ss;
if_ss           = i_ss+phi_u_ss*k_ss/a_ss;
o_ss            = cO_ss+xO_ss;
pYy_ss          = (...
                   pH_ss*yHtil_ss+pO_ss*(cO_ss)+yHstarVA_ss-rer_ss*pOstar_ss*o_ss...
                   +pF_ss*(1-mcF_ss*DelF_ss)*(...
                                               +O_I*(pF_ss/pI_ss)^-ETA_I*if_ss...
                                               +O_Co* (pF_ss/pICo_ss)^(-ETA_Co)*utCo_ss...
                                               -O_Z*(pF_ss/pZ_ss)^-ETA_Z*(1-KAPPA_O-KAPPA_A)*pZ_ss^-ETA_C*(pI_ss*if_ss+pICo_ss*utCo_ss)...
                                               -O_A*(pF_ss/pA_ss)^-ETA_A*(KAPPA_A)          *pA_ss^-ETA_C*(pI_ss*if_ss+pICo_ss*utCo_ss)...                                            
                                              )...
                  )...
                 /( ...
                   1-sYCo_ss-pF_ss*(1-mcF_ss*DelF_ss)*(...
                                                       O_Z * (pF_ss/pZ_ss)  ^(-ETA_Z)  *(1-KAPPA_O-KAPPA_A)*pZ_ss^-ETA_C*(1-stb_ss-scG_ss-siCo_ss)...
                                                      +O_A * (pF_ss/pA_ss)  ^(-ETA_A)  * KAPPA_A           *pA_ss^-ETA_C*(1-stb_ss-scG_ss-siCo_ss)...
                                                      +O_G * (pF_ss/pG_ss)  ^(-ETA_G)  * scG_ss/pG_ss...
                                                      +O_Co* (pF_ss/pICo_ss)^(-ETA_Co) * siCo_ss/pICo_ss...
                                                     )...
                  );
tb_ss           = stb_ss*pYy_ss;
cG_ss           = scG_ss*pYy_ss/pG_ss;
yCo_ss          = sYCo_ss*pYy_ss/(rer_ss*pCostar_ss);
iCo_ss          = siCo_ss*pYy_ss/pICo_ss;
qCo_ss          = pICo_ss/varomegaCo_ss/varomegaCo2_ss; 


%61-70
kCo_ss          = sKCo_ss*yCo_ss*(rer_ss*pCostar_ss)/qCo_ss;
DELTA_Co        = varomegaCo_ss*varomegaCo2_ss*iCo_ss*a_ss/kCo_ss-a_ss+1;
uCo_ss          = 1- log(pICo_ss)/PHI_UCo;   
ALPHA_Co        = qCo_ss*(a_ss^SIGMA/BETTA-(1-DELTA_Co))*kCo_ss/a_ss...
                  /((1-TAU_Co*(1-CHI_Co))*rer_ss*pCostar_ss*yCo_ss);                                 
rKCo_ss         = (1-TAU_Co*(1-CHI_Co))*rer_ss*pCostar_ss*ALPHA_Co*yCo_ss/uCo_ss/kCo_ss*a_ss;
phi_uCo_ss      = rKCo_ss/PHI_UCo*(exp(PHI_UCo*(uCo_ss-1))-1);  
iCof_ss         = iCo_ss+phi_uCo_ss*kCo_ss/a_ss;
zCo_ss          = (uCo_ss*kCo_ss/a_ss)^-ALPHA_Co*(a_ss*wedCo_ss*L_BAR)^(ALPHA_Co-1)*yCo_ss;
cfCo_ss         = rer_ss*pCostar_ss*yCo_ss-pICo_ss*iCof_ss;
renstar_ss      = sca_ss*pYy_ss/rer_ss*(a_ss*pistar_ss-Rstar_ss*xi_ss)/(a_ss*pistar_ss-1)...
                 -tb_ss/rer_ss;
 
            
%71-80             
xiREN_ss        = ((1-CHI_Co)*(cfCo_ss-TAU_Co*(cfCo_ss+pICo_ss*iCof_ss))/rer_ss...
                  +renstar_ss)/(1-OMEGA);
renRstar_ss     = xiREN_ss;
c_ss            = pYy_ss-pG_ss*cG_ss-pI_ss*if_ss-pICo_ss*iCof_ss-tb_ss;
cZ_ss           = (1-KAPPA_O-KAPPA_A)*(pZ_ss)        ^-ETA_C *c_ss;
cA_ss           = (KAPPA_A)          *(pA_ss)        ^-ETA_C *c_ss;
xZH_ss          = (1-O_Z)            *(pH_ss/pZ_ss)  ^-ETA_Z *cZ_ss;
xZF_ss          = (O_Z)              *(pF_ss/pZ_ss)  ^-ETA_Z *cZ_ss;
xAH_ss          = (1-O_A)            *(pH_ss/pA_ss)  ^-ETA_A *cA_ss*zA_ss^(ETA_A-1);
xAF_ss          = (O_A)              *(pF_ss/pA_ss)  ^-ETA_A *cA_ss*zA_ss^(ETA_A-1);
xGH_ss          = (1-O_G)            *(pH_ss/pG_ss)  ^-ETA_G *cG_ss;


%81-90
xGF_ss          = (O_G)              *(pF_ss/pG_ss)  ^-ETA_G *cG_ss;
xIH_ss          = (1-O_I)            *(pH_ss/pI_ss)  ^-ETA_I *if_ss;
xIF_ss          = (O_I)              *(pF_ss/pI_ss)  ^-ETA_I *if_ss;
xCoH_ss         = (1-O_Co)           *(pH_ss/pICo_ss)^-ETA_Co*iCof_ss;	
xCoF_ss         = (O_Co)             *(pF_ss/pICo_ss)^-ETA_Co*iCof_ss;
xH_ss           = xZH_ss+xAH_ss+xGH_ss+xIH_ss+xCoH_ss;
yH_ss           = xH_ss;
yHstar_ss       =(yHtil_ss-yH_ss*DelH_ss)/DelHstar_ss;
xHstar_ss       = yHstar_ss;
xF_ss           = xZF_ss+xAF_ss+xGF_ss+xIF_ss+xCoF_ss;


%91-100
yF_ss           = xF_ss;
fW_ss           = wtil_ss      ^-EPSILON_W     *hd_ss*mcW_ss         /(1-BETTA*a_ss^(1-SIGMA)*THETA_W);
fH_ss           = ptilH_ss     ^-EPSILON_H     *yH_ss*mcH_ss         /(1-BETTA*a_ss^(1-SIGMA)*THETA_H);
fF_ss           = ptilF_ss     ^-EPSILON_F     *yF_ss*mcF_ss         /(1-BETTA*a_ss^(1-SIGMA)*THETA_F);
fHstar_ss       = ptilHstar_ss ^-EPSILON_Hstar *yHstar_ss*mcHstar_ss /(1-BETTA*a_ss^(1-SIGMA)*THETA_Hstar);
m_ss            = yF_ss*DelF_ss;
y_ss            = c_ss+cG_ss+if_ss+iCof_ss+yHstar_ss+yCo_ss-m_ss-o_ss;
yC_ss           = c_ss+pG_ss*cG_ss+pI_ss*if_ss+pICo_ss*iCof_ss;
pY_ss           = (yC_ss+tb_ss)/y_ss;
dstar_ss        = - sca_ss*pYy_ss*a_ss*pistar_ss/rer_ss/(a_ss*pistar_ss-1);


%101-110
ystar_ss        = a_ss*zstar_ss;
OSTAR           = xHstar_ss*pHstar_ss^ETASTAR/ystar_ss/xiXHstar_ss^(1/(1-RHO_XHstar));	
g_ss            = pG_ss*cG_ss+(rer_ss*pOstar_ss-pO_ss)*o_ss;
d_ss            = pYy_ss-rer_ss*pCostar_ss*yCo_ss-(pO_ss-rer_ss*pOstar_ss)*o_ss-rK_ss*kS_ss-w_ss*hd_ss;
b_ss            = sDEF_ss*pY_ss*y_ss/((1-1/(a_ss*pi_ss))+ALPHA_D/(1-ALPHA_D)*(1-1/(a_ss*pistar_ss)));
dstarG_ss 		= ALPHA_D/(1-ALPHA_D)*b_ss/rer_ss;
tau_ss          = g_ss + b_ss*(R_ss/(a_ss*pi_ss)-1)+rer_ss*dstarG_ss*(Rstar_ss*xi_ss/(a_ss*pistar_ss)-1)...
                  -CHI_Co*cfCo_ss;
t_ss            = tau_ss-TAU_C*c_ss-TAU_W*w_ss*hd_ss...
                 -TAU_K*(rK_ss*u_ss-pI_ss*(DELTA+phi_u_ss))*k_ss/a_ss...
				 -TAU_D*d_ss - TAU_Co*(1-CHI_Co)*(cfCo_ss+pICo_ss*iCof_ss);
ALPHA_T         = t_ss/pYy_ss;
                                    
cNR_ss          = ((1-TAU_W)*w_ss*hd_ss-t_ss*OMEGA_G/OMEGA)/(1+TAU_C)                     ;%% SS_53-2-3-12				

imp_ss=yF_ss*DelF_ss;

%111-120
cR_ss           = (c_ss-OMEGA*cNR_ss)/(1-OMEGA);      
lamR_ss         = (cR_ss-VARSIGMA*cR_ss/a_ss)^(-SIGMA)/(1+TAU_C)       ;%% SS_44-3       
lamNR_ss        = (cNR_ss-VARSIGMA*cNR_ss/a_ss)^(-SIGMA)/(1+TAU_C)   ;%% SS_54-3
lamU_ss         = OMEGA_U*lamNR_ss + (1-OMEGA_U)*lamR_ss                    ;%% SS_55-2	
kappa_ss        = mcW_ss*lamU_ss*(1-TAU_W)*w_ss/hd_ss^PHI/wedH_ss^(1-SIGMA);%% SS_43
    % guess parameters   
UPD             = 1;
utCo_ss_upd     = phi_uCo_ss*kCo_ss/a_ss;
utCo_ss_upd     = utCo_ss_upd^UPD*utCo_ss^(1-UPD);
yHstarVA_ss_upd	= (pHstar_ss*rer_ss-pH_ss)*yHstar_ss;
yHstarVA_ss_upd = yHstarVA_ss_upd*UPD+yHstarVA_ss*(1-UPD);
kS_ss_upd       = ALPHA/(1-ALPHA)*w_ss*hd_ss/rK_ss;
kS_ss_upd       = kS_ss_upd^UPD*kS_ss^(1-UPD);
cO_ss_upd       = KAPPA_O*pO_ss^-ETA_C*c_ss;
cO_ss_upd       = cO_ss_upd*UPD+cO_ss*(1-UPD);
xO_ss_upd       = z_ss^(ETA_O-1)*ALPHA_O*(pO_ss/pHtil_ss)^-ETA_O*yHtil_ss;
xO_ss_upd       = xO_ss_upd*UPD+xO_ss*(1-UPD);
 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% other ss eqs %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%% Balanced growth path variables
[gam_C_ss,      ...
 gam_CG_ss,     ...
 gam_I_ss,      ...
 gam_ICo_ss,    ...
 gam_W_ss,      ...
 gam_Y_ss,      ...
 gam_YCo_ss,    ...
 gam_YR_ss,     ...
 gam_Ystar_ss]  = deal(a_ss);

%%%%%%%% Inflation variables
[piH_ss,        ...
 piF_ss,        ...
 piA_ss,        ...
 piMtot_ss,     ...
 piO_ss]      = deal(pi_ss);

[piCostar_ss,   ...
 piOstar_ss,    ...
 piMstar_ss,    ...
 pistartil_ss,  ...
 piHstar_ss]    = deal(pistar_ss);

%%%%%%%% other
sdstar_ss       = rer_ss*dstar_ss/pYy_ss;

