function resid = ststsw03(X);
  resid = 0;
beta = 0.99;
alpha = 0.3;
tau = 0.025;
h = 0.592;
sigma_c = 1.391;
gamma_p = 0.477;
gamma_w = 0.728;
xi_p = 0.905;
xi_w = 0.742;
sigma_L = 2.503;
varphi = 6.962;
r_bar = (1 / beta - 1) + tau;
piStSt = 1;
psi = 0.201;
phi = 1.417;
rho = 0.956;
r_pi = 1.688;
r_Y = 0.098;
r_delta_pi = 0.151;
r_delta_y = 0.158;
g_y = 0.2;
k_y = 12;
rho_b = 0.838;
rho_L = 0.881;
rho_I = 0.91;
rho_a = 0.811;
lambda_w = 0.5;
lambda_p = phi - 1;
rho_G = 0.943;
rho_pi = 0.855;
  eta_b = 0;
  eta_L = 0;
  eta_I = 0;
  eta_a = 0;
  eta_w = 0;
  eta_p = 0;
  eta_G = 0;
  eta_pi = 0;
  eta_R = 0;
  eta_Q = 0;
L = X(1)
  z = 1;
  mc = 1/(1+lambda_p);
  pi = piStSt;
  wpi = pi;
  eps_b = exp(-eta_b/(rho_b - 1));
  eps_L = exp(-eta_L/(rho_L - 1));
  eps_I = exp(-eta_I/(rho_I - 1));
  eps_a = exp(-eta_a/(rho_a - 1));
  lambda_pt = lambda_p + eta_p;
  lambda_wt = lambda_w + eta_w;
  eps_G = (g_y*rho_G - g_y - eta_G)/(rho_G - 1);
  pi_bar = (piStSt*rho_pi - piStSt - eta_pi)/(rho_pi - 1);
  Q = 1;
  rK = tau - 1 + 1/beta;
  constz = rK;
  w = (alpha^alpha*(-alpha + 1)^(-alpha + 1)*mc*rK^(-alpha))^(-1/(alpha - 1));
  K = -alpha*L*w/((alpha - 1)*rK);
  I = tau*K;
  fixcost = (K*z)^alpha*(phi - 1)*L^(-alpha + 1)*eps_a/phi ;
  Y = -fixcost + K^alpha*L^(-alpha + 1)*eps_a;
  Lstst = L ;
  Y_p = Lstst^(-alpha + 1)*(K*z)^alpha*eps_a - fixcost;
  C = -I - Y*eps_G + Y;
  H = h*C;
  lambda = (C - H)^(-sigma_c)*eps_b;
  R = exp((r_Y*rho*log(Y/Y_p) - r_Y*log(Y/Y_p) + r_pi*rho*log(pi/pi_bar) - r_pi*log(pi/pi_bar) + rho*log(pi_bar/beta) - eta_R - log(pi_bar/beta))/(rho - 1));
  UL = L^sigma_L*eps_L*eps_b;
  ptau = 1;
  APtilde = -Y*lambda*ptau^(-1/(lambda_p + 1))/(beta*xi_p*(pi^(gamma_p - 1))^(lambda_p/(lambda_p + 1)) - 1);
  BPtilde = (lambda_p + 1)*(pi^(gamma_p - 1))^(1/(lambda_p + 1))*Y*lambda*mc*ptau^(-1/(lambda_p + 1))/(-beta*xi_p + (pi^(gamma_p - 1))^(1/(lambda_p + 1)));
  AP = beta*xi_p*(pi^gamma_p/pi)^(lambda_p/(lambda_p + 1))*APtilde + Y*lambda*ptau^(-1/(lambda_pt + 1));
  BP = beta*xi_p*(pi^gamma_p/pi)^(-1/(lambda_p + 1))*BPtilde + Y*lambda*lambda_pt*mc*ptau^(-1/(lambda_pt + 1)) + Y*lambda*mc*ptau^(-1/(lambda_pt + 1));
  wtau = w;
  AWtilde = -(wtau/w)^(-1/(lambda_w + 1))*L*lambda*pi/(beta*lambda_w*xi_w*pi^(gamma_w*lambda_w/(lambda_w + 1))*wpi^(1/(lambda_w + 1)) + beta*xi_w*pi^(gamma_w*lambda_w/(lambda_w + 1))*wpi^(1/(lambda_w + 1)) - lambda_w*pi - pi);
  BWtilde = (pi^gamma_w/wpi)^(1/(lambda_w + 1))*(wtau/w)^(-1/(lambda_w + 1))*L*UL/(-beta*xi_w + (pi^gamma_w/wpi)^(1/(lambda_w + 1)));
  AW = (wtau/w)^(-1/(lambda_wt + 1))*(beta*xi_w*(wtau/w)^(1/(lambda_wt + 1))*AWtilde*lambda_wt*pi^(gamma_w*lambda_w/(lambda_w + 1))*wpi^(1/(lambda_w + 1)) + beta*xi_w*(wtau/w)^(1/(lambda_wt + 1))*AWtilde*pi^(gamma_w*lambda_w/(lambda_w + 1))*wpi^(1/(lambda_w + 1)) + L*lambda*pi)/((lambda_wt + 1)*pi);
  BW = beta*xi_w*(pi^gamma_w/wpi)^(-1/(lambda_w + 1))*BWtilde + (wtau/w)^(-1/(lambda_wt + 1))*L*UL;
  fprintf(1,'%s: %e\n','popt',-AP*ptau + BP);
  fprintf(1,'%s: %e\n','dynP',xi_p*(pi^gamma_p)^(-1/lambda_pt) - pi^(-1/lambda_pt) + (pi*ptau)^(-1/lambda_pt)*(-xi_p + 1));
  fprintf(1,'%s: %e\n','ww',1 - wpi/pi);
  fprintf(1,'%s: %e\n','dynW',xi_w*(pi^gamma_w)^(-1/lambda_wt) - wpi^(-1/lambda_wt) + (wtau/w)^(-1/lambda_wt)*(-xi_w + 1));
  resid = -AW*wtau + BW;
global params;
 params =  struct('beta',beta,'alpha',alpha,'tau',tau,'h',h,'sigma_c',sigma_c,'gamma_p',gamma_p,'gamma_w',gamma_w,'xi_p',xi_p,'xi_w',xi_w,'sigma_L',sigma_L,'varphi',varphi,'r_bar',r_bar,'piStSt',piStSt,'psi',psi,'phi',phi,'rho',rho,'r_pi',r_pi,'r_Y',r_Y,'r_delta_pi',r_delta_pi,'r_delta_y',r_delta_y,'g_y',g_y,'k_y',k_y,'rho_b',rho_b,'rho_L',rho_L,'rho_I',rho_I,'rho_a',rho_a,'lambda_w',lambda_w,'lambda_p',lambda_p,'rho_G',rho_G,'rho_pi',rho_pi,'Lstst',Lstst,'fixcost',fixcost,'constz',constz);
  varnames = {'mc','pi','wpi','w','K','Q','I','C','R','L','Y','Y_p','pi_bar','eps_b','eps_L','eps_I','eps_a','lambda_pt','lambda_wt','lambda','UL','eps_G','H','wtau','ptau','rK','z','AP','APtilde','BP','BPtilde','AW','AWtilde','BW','BWtilde'};
FFS = fopen('ststini.m','w');
for ii = 1:length(varnames)
varname = varnames{ii};
eval(['x_ = ' varname ';']);
fprintf(FFS,'    %s = %0.12f;\n',varname,x_);
end
fclose(FFS);
FFS = fopen('parcali.m','w');
caliPars = {'Lstst','fixcost','constz'};
for ii = 1:length(caliPars)
varname = caliPars{ii};
eval(['x_ = ' varname ';']);
fprintf(FFS,'    %s = %0.12f;\n',varname,x_);
end
fclose(FFS);

end
