
% global rho_govc_val rho_v_val rho_betavar_val eta_val nu_val

% syms alpha_m alpha_n alpha_nc alpha_ni betap delta_m delta_n a_n2a_m

r_ss     = gam*pi_n_ss / betap;

mc_m_ss  = 1/z_m_ss;
mc_n_ss  = 1/z_n_ss;


% -------------------
X1 = (mc_n_ss/mc_m_ss*(1 - alpha_n)/(1 - alpha_m)*a_n_ss/a_m_ss*(mc_n_ss*alpha_n)^(alpha_n/(1 - alpha_n))/(mc_m_ss*alpha_m)^(alpha_m/(1 - alpha_m))*((gam/betap - (1 - delta_m))/(1-tau_ss))^((alpha_m)/(1 - alpha_m))/((gam/betap - (1 - delta_n))/(1-tau_ss))^((alpha_n)/(1 - alpha_n)))^(1 - alpha_m);

X2 = 1/(1 - psi)*(alpha_m - alpha_n)/(1 - alpha_n);

pm_pn_ss = SS_LS1_aux(X1, X2, alp, psi);

    
% from equation 41
p_n_ss = 1;
p_m_ss = pm_pn_ss*p_n_ss;
p_ss   = ((1 - alp)^psi*p_m_ss^(1 - psi) + alp^psi*p_n_ss^(1 - psi))^(1/(1 - psi));

r_n_ss = p_ss*(gam/betap - (1 - delta_n))/(1-tau_ss);
r_m_ss = p_ss*(gam/betap - (1 - delta_m))/(1-tau_ss);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the mistake must be between lines 65 and 76

k_n2y_n_ss = mc_n_ss*gam*alpha_n*p_n_ss/r_n_ss;
k_m2y_m_ss = mc_m_ss*gam*alpha_m*p_m_ss/r_m_ss;

y_m2y_ss = (1 - alp)^psi*(p_m_ss/p_ss)^(-psi);
y_n2y_ss = alp^psi*(p_n_ss/p_ss)^(-psi);

y_n2y_m_ss = y_n2y_ss/y_m2y_ss;

l_m2l_ss = ( mc_m_ss*(1-alpha_m)*p_m_ss/p_n_ss )/(mc_m_ss* (1-alpha_m)*p_m_ss/p_n_ss + mc_n_ss* (1-alpha_n)*y_n2y_m_ss ) ;

l_n2l_ss = 1 - l_m2l_ss;

l_m_ss = l_m2l_ss *l_ss;

l_n_ss = l_n2l_ss *l_ss;

y_n2l_n_ss = a_n_ss*(mc_n_ss*alpha_n*p_n_ss/r_n_ss)^(alpha_n/(1-alpha_n));
y_m2l_m_ss = a_m_ss*(mc_m_ss*alpha_m*p_m_ss/r_m_ss)^(alpha_m/(1-alpha_m));

y_n_ss = y_n2l_n_ss*l_n_ss;
y_m_ss = y_m2l_m_ss*l_m_ss;

k_n_ss = k_n2y_n_ss*y_n_ss;
k_m_ss = k_m2y_m_ss*y_m_ss;
 
invest_ss = (1 - (1 - delta_m)/gam)*k_m_ss + (1 - (1 - delta_n)/gam)*k_n_ss;
y_ss = (p_n_ss*y_n_ss + p_m_ss*y_m_ss)/p_ss;
s_ss = invest_ss/y_ss;        % 储蓄率
c_ss = (1 - s_ss - g2y_ss)*y_ss  ;

w_ss = p_n_ss*mc_n_ss*(1-alpha_n)*y_n_ss/l_n_ss;

% --------------------
% fiscal block
% --------------------
b_m_ss    = sb_ss*y_ss*p_ss;
b_m       = b_m_ss;
tax_ss    = tau_ss*(r_m_ss*k_m_ss/gam + r_n_ss*k_n_ss/gam + w_ss*l_ss)   ;   % tax revnue
pb_ss     = 1/(pi_n_ss*gam/betap - rho);   % price of long-run bond
tra_ss    =  (1 - (1/pb_ss + rho)/pi_n_ss/gam)*b_m_ss/p_ss + tax_ss/p_ss - govc_ss;   % Transfer

% Rule of thumb
c_r_ss   = (w_ss*l_ss + p_ss*tra_ss)/p_ss;
c_o_ss   = (c_ss - lam*c_r_ss)/(1 - lam);
cstar_ss = c_o_ss + alp_g*govc_ss;

lambda_c_ss = (1 - eta*betap/gam)/(1 - eta/gam)/(p_ss*cstar_ss);
lambda_k_ss = -lambda_c_ss*p_ss;

% choice of chi_0 supports the choice of l made above
chi_0 = lambda_c_ss*w_ss*(1-tau_ss)/(l_ss^chi);

%% 价格辅助
p_mstar_ss  = 1   ;  % 17最优价格
th1_m_ss    = p_m_ss/(1-betap*xi_m_ss);  % 18辅助
th2_m_ss    = p_m_ss/(1-betap*xi_m_ss);  % 19辅助
p_mM_ss     = 1   ;  % 20维持价格

p_nstar_ss  = 1   ;  % 28最优价格
th1_n_ss    = p_n_ss/(1-betap*xi_n_ss);  % 29辅助
th2_n_ss    = p_n_ss/(1-betap*xi_n_ss);  % 30辅助
p_nM_ss     = 1   ; % 31维持价格


%% -------------------
%  SS
% --------------------
c = c_ss;       % 1-消费
invest=invest_ss;     % 2-投资
p=p_ss;        % 3-消费品相对价格
r_n=r_n_ss;        % 4-非服务资本租金率
r_m=r_m_ss;        % 5-服务资本租金率
lambda_c=lambda_c_ss;   % 6-预算约束拉格朗日乘数
lambda_k=lambda_k_ss;   % 7-资本运动方程拉个朗日乘数
    
r = r_ss;          % 9-利率
w = w_ss;          % 10-工资
l = l_ss;          % 11-劳动
k_m=k_m_ss;        % 12-服务业资本
k_n=k_n_ss;        % 13-非服务资本
l_m=l_m_ss;        % 14-服务业劳动
l_n=l_n_ss;        % 15-非服务劳动
y_m=y_m_ss;        % 16-服务实际产出
y_n=y_n_ss;        % 17-非服务实际产出
    
p_m=p_m_ss;        % 18-服务相对价格
p_n=p_n_ss;        % 19-非服务相对价格
   
mc_m=mc_m_ss;       % 26-服务品实际边际成本
mc_n=mc_n_ss;       % 27-非服务实际边际成本

% 服务企业定价
p_mstar=p_mstar_ss;     % 28-最优价格
th1_m=th1_m_ss;       % 29-辅助
th2_m=th2_m_ss;       % 30-辅助
p_mM=p_mM_ss;        % 31-维持价格
xi_m=xi_m_ss;        % 32-调价概率 
pi_m=pi_m_ss;        % 33-服务通胀

% 非服务企业定价 
p_nstar=p_nstar_ss;     % 34-最优价格
th1_n=th1_n_ss;       % 35-辅助
th2_n=th2_n_ss;       % 36-辅助
p_nM=p_nM_ss;        % 37-维持价格
xi_n=xi_n_ss;       % 38-调价概率
pi_n=pi_n_ss;        % 39-非服务通胀 


%% Final
pi = pi_ss;        % 40-消费品价格通胀
y  = y_ss;          % 47-总产出

s_m = 1;
s_n = 1;

govc= govc_ss   ;   % 1-政府消费
tax = tax_ss    ;   % tax revnue
tra = tra_ss    ;   % 48-转移支付
tau = tau_ss    ;   % 49-税率
def = -(tax_ss/p_ss - govc_ss - tra_ss)/y_ss ;       % 50-赤字
sb  = sb_ss     ;   % 51-长期债务占产出比值
pb  = pb_ss     ;   % 52-长期债券价格

c_r   = c_r_ss;
c_o   = c_o_ss;
cstar = cstar_ss;
Ngam  = gam ;

Lambda = 0; % 49-$\lambda$   (long_name='Lagrange multiplier')
% --------------------
% 外生冲击
% --------------------
a_m = a_m_ss;         % 1-服务劳动生产率冲击
a_n = a_n_ss;         % 2-非服务劳动生产率冲击
z_m = z_m_ss;        % 3-服务品价格加成冲击
z_n = z_n_ss;        % 4-非服务价格加成冲击

betavar = 1;     % 6-偏好冲击
z_m2 = 1;         % 7-货币政策冲击
z_k  = 1;         % 8-投资冲击

ugovc = 1;
utau  = 1;
%% --------------------
% --- Shadow economy
% --------------------
cF   = c_ss;          % 1-消费
investF = invest_ss;     % 2-投资
pF   = p_ss;        % 3-消费品相对价格
r_nF = r_n_ss ;        % 4-货物资本租金率
r_mF = r_m_ss;        % 5-服务资本租金率
lambda_cF = lambda_c_ss;   % 6-预算约束拉格朗日乘数
lambda_kF = lambda_k_ss;   % 7-资本运动方程拉个朗日乘数

rF = r_ss;          % 9-利率
wF = w_ss;          % 10-工资
lF = l_ss;          % 11-劳动
k_mF = k_m_ss;        % 12-服务业资本
k_nF = k_n_ss;        % 13-货物资本
l_mF = l_m_ss;       % 14-服务业劳动
l_nF = l_n_ss;        % 15-货物劳动
y_mF = y_m_ss;        % 16-服务实际产出
y_nF = y_n_ss;        % 17-货物实际产出
    
p_mF = p_m_ss;        % 18-服务相对价格
p_nF = p_n_ss;        % 19-货物相对价格

mc_mF = mc_m_ss;       % 20-服务品实际边际成本
mc_nF = mc_n_ss;       % 21-货物实际边际成本

% 服务企业定价
p_mstarF = p_mstar_ss;     % 22-最优价格
th1_mF   = th1_m_ss;       % 23-辅助
th2_mF   = th2_m_ss;       % 24-辅助
p_mMF    = p_mM_ss;        % 25-维持价格
xi_mF    = xi_m_ss;        % 26-调价概率 
pi_mF    = pi_m_ss;        % 27-服务通胀
s_mF     = 1;         % 28-

% 货物企业定价 
p_nstarF = p_nstar_ss;     % 29-最优价格
th1_nF   = th1_n_ss;       % 30-辅助
th2_nF   = th2_n_ss;       % 31-辅助
p_nMF    = p_nM_ss;        % 32-维持价格
xi_nF    = xi_n_ss;        % 33-调价概率
pi_nF    = pi_n_ss;        % 34-货物通胀
s_nF     = 1;         % 35-

%
piF = pi_ss;       % 36-总体价格通胀

sF = s_ss;          % 42-消费品价值占比
yF = y_ss;          % 43-总产出


% 财政变量
b_mF  = b_m_ss;         % 46-长期债券
taxF  = tax_ss;         % 47-税收
govcF = govc_ss;        % 48-政府消费
traF  = tra_ss;         % 49-转移支付
tauF  = tau_ss;         % 50-税率
defF  = def ;         % 51-赤字
sbF   = sb_ss;          % 52-长期债务占产出比值
pbF   = pb_ss;          % 53-长期债券价格

% 扩展变量
c_oF = c_o_ss;         % 1-储蓄者消费
c_rF = c_r_ss;         % 2-非储蓄者消费
cstarF = cstar_ss;       % 3-合成消费




