function resid = merzstst(x)
  N = x(1);
  S = x(2);

  % set the parameters:
  alpha = 0.36;
  beta = 0.99;
  delta = 0.022;
  eta = 1;
  nu = -1.25;
  lambda = 0.4;
  psi = 0.07;
  mu = 0.004;
  a = 0.05;
  c0 = 0.005;
  rho = 0.95;
  gam = 1;
  deltaprime = 1-(1-delta)*exp(-mu);

  % define some functions, for convenience:
  pow = @(a,b) a^b;
  U_c = @(c,l) pow(c,-gam);
  F =   @(z,k,l) exp((1-alpha)*z)*pow(k,alpha)*pow(l,(1-alpha));
  F_k = @(z,kl) alpha*exp((1-alpha)*z)*pow(kl,alpha-1);
  F_L = @(z,kl) (1-alpha)*exp((1-alpha)*z)*pow(kl,alpha);
  scost = @(S)  c0*pow(S,eta);
  scost_s = @(S) c0*eta*pow(S,eta-1);

  % compute all other variables:
  M = psi*N;
  V = M^(1/(1-lambda)) * (S*(1-N))^(lambda/(lambda-1));

  p = M / (S * (1-N));
  q = M / V;
  z = 0;

  r = 1/beta - 1 + deltaprime;
  % solve r = alpha * kl^(alpha-1);
  kl = (alpha/r)^(1/(1-alpha));
  k = kl*N;
  y = pow(k,alpha)*pow(N,(1-alpha));
  I = deltaprime*k;
  c =  y - (I + a*V + scost(S)*(1-N));
  MUC = c^(-gam);
  mdisu=  pow(N,-1/nu);
  w = lambda*(F_L(z,kl) + a*V/(1-N)) + (1-lambda)*(mdisu/MUC - scost(S));
  mpn = F_L(z,kl);
  U = 1 -N;
  probFind = p*S;
  AveLabProd = y/N;

  varnames = { 'N',' z',' M',' p',' q',' r',' y',' I',' k',' V',' w',' S',' c','U'};
  FSTST = fopen('ststres.m','w');
  for ii = 1:length(varnames)
    varname = varnames{ii};
    eval(['x_ = ' varname ';']);
    fprintf(FSTST,'%s = %0.12f;\n',varname,x_);
  end
  fclose(FSTST)

  % the residuals: equations H2 and F2:
  resid1 = -MUC*scost_s(S) +  p*beta*(MUC*(w+scost(S)) - mdisu  + MUC*scost_s(S)/p*(1-psi-p*S));
  resid2 = -a*MUC + q*beta*MUC*(mpn- w + 	a/q*(1-psi));
  % return residual as column vector:
  resid = [resid1;resid2]
end


%% z &= rho*z + epsilon;
%% 
%% # employment:
%% # new matches:
%% M &= match(V,N,S);
%% p &= M / (S * (1-N));
%% 
%% # Household Euler equation H1:
%% euler: U_c(c,N) &= beta*(1+r - deltaprime)*U_c(c,N);
%% # Optimal capital input: gross interest rate = marginal productivity of capital:
%% r &= F_k(z,kl);
%% 
%% # Production function
%% y &= F(z,k,N);
%% # Law of motion for capital:
%% k &= kl * N;
%% # Aggregate resource constraint:
%% c &=  y - (I + a*V + c0*pow(S,eta)*(1-N));
%% 
%% 
%% 
%% 
%% #wage equation, p.291:
%% 
%% 
%% # unemployment rate:
%% 
%% # job finding rate:
%% 
%% # Average labor productivity:
%% 
%% 
