function [d out] = stst(val,par)

% MODEL PARAMETERS

%global par
bet = par.bet;
the = par.the;
 mu = par.mu;
phi = par.phi;
psi = par.psi;
del = par.del;
sig = par.sig;
alf = par.alf;
gam = par.gam;
  Q = par.Q;
  H = par.H;

%  ENDOGENOUS VARIABLES

 c = val(1);
 n = val(2);
 i = val(3);
 s = val(4);
xi = val(5);

% MODEL SS EQUATIONS

z = 1;
eta = 1;
r = 1/bet-1+phi*s;
R = (1-bet)/bet*(1/psi)*del^((1-psi)/psi)+del^(1/psi);
K = i/del^(1/psi);

% Marginal utility of consumption
Uc = mu*c^(the*mu-1)*(1-n)^(the*(1-mu));

% Marginal (dis)utility of labor
Un = -(1-mu)*c^(the*mu)*(1-n)^(the*(1-mu)-1); 

% FOC for labor
w = -Un/Uc; 

% Final good production
Y = c + i;

% Capital demand
k = K;

% Labor demand
l = n - Q;

% Raw input production
f = k^gam*l^(1-gam);

% Raw input prices
P = w/((1-gam)*(k/l)^(gam));

% Lambda
lam = alf/(1-alf)*(1-xi*H*eta-xi)/(1-xi*H*eta)*(1+r);

% Price of intermediate goods
p = 1/(sig*lam^alf)*(lam*P + (1+r)*P);

% Demand for intermediates
d = Y*p^(1/(sig-1));

% Demand for foreign inputs
x = d/(lam^(alf));

% Demand for domestic inputs
h = lam*x;

% Intermediate good firm profits
pi = p*d - P*h - (1+r)*P*x - Q*w;

% Household's budget constraint (c)
d1 = c + i + s + phi/2*s^2 - (w*n + pi + s*(1+r) + K*R);

% Savings markets clear (r)
d2 = s - P*x;

% Rental price of capital (R)
d3 = R - gam*P*(k/l)^(gam-1);

% Good market clearing (n)
d4 = h + x - f;

% FOC for Lagrangian multiplier (xi)
d5 = H*eta*pi-(1+r)*P*x;

d = [d1 d2 d3 d4 d5]';

out.z = z;
out.eta = eta;
out.R = R;
out.r = r;
out.K = K;
out.p = p;
out.P = P;
out.x = x;

% NATIONAL ACCOUNTING

% Exports (ex,rex)
out.ex = P*x;

% GDP (gdp,rgdp)
out.gdp = Y;

% Consumption/GDP
out.cpct = c/Y;

% Investment/GDP
out.ipct = i/Y;

% (Imports or Exports)/GDP
out.xpct = P*x/Y;

% Terms of trade (tot)
out.tot = 1;

% Real exchange rate (rer)
out.rer = 1;

% Net exports (nx,rnx)
out.nx = 0;

% Relative consumption (RC)
out.RC = 1;


end




