function f = ssfocm(Z,PARAMS);

% Are discrimination revenues transferred (tran=1) or given
% to married males (tran=0)?

tran   = 0;

%
% Endogenous variables
%
nx0    = 30;
npar0  = 47;
X      = PARAMS(nx0+1:2*nx0);
xon    = find(PARAMS(1:nx0));
X(xon) = Z(1:length(xon));
P      = PARAMS(2*nx0+npar0+1:2*nx0+2*npar0);
pon    = find(PARAMS(2*nx0+1:2*nx0+npar0));
P(pon) = Z(length(xon)+1:nx0);

l1fp   = X(1);
l1mp   = X(2);
l1fs   = X(3);
l1ms   = X(4);
l2fp   = X(5);
l2fs   = X(6);
l2ms   = X(7);
c1fp   = X(8);
c1mp   = X(9);
c1fs   = X(10);
c1ms   = X(11);
c2fp   = X(12);
c2mp   = X(13);
k1p    = X(14);
k1fs   = X(15);
k1ms   = X(16);
k2p    = X(17); 
k2fs   = X(18);
k2ms   = X(19);
hfp    = X(20);
hmp    = X(21);
hfs    = X(22); 
hms    = X(23);
efp    = X(24);
emp    = X(25);
efs    = X(26); 
ems    = X(27);
T      = X(28);
if tran==1;
  Td     = X(29);
  taulmp = P(33);
else
  Td     = 0;
  taulmp= X(29);
end;
relw   = X(30);

%
% Parameters
%

nper   = P(2);
np     = P(3);
nfs    = P(4);
nms    = 1-2*np-nfs;
beta   = P(5);
delh   = P(6);
dele   = P(7);
delk   = P(8);
kap1   = P(9);
zet1   = P(10);
kap2   = P(11);
zet2   = P(12);
b1f    = P(13);
b2f    = P(14);
b1m    = P(15);
b2m    = P(16);
lam    = P(17);
theta1 = P(18);
mtech  = P(19);
theta2 = P(20);
htech  = P(21);
util   = P(22);
upar   = P(23:26);
gpar   = P(27:29);
g      = P(30);
tauk   = P(31);
taulfp = P(32);
taulfs = P(34);
taulms = P(35);
Tp     = P(36)*T;
Tfs    = P(37)*T;
Tms    = T-Tp-Tfs;
Tdp    = P(38)*Td;
Tdfs   = P(39)*Td;
Tdms   = Td-Tdp-Tdfs;
gama   = P(40);
gamp   = P(41);
gam    = gama+gamp+gama*gamp;
beth   = beta*(1+gama)^((1-upar(3))*(1-upar(4))-1);
qk1    = P(42);
qk2    = P(43);
qh     = P(44);
qe     = P(45);
res1   = P(46);
res2   = P(47);
if res1;
  zet1 = kap1;
end;
if res2;
  zet2 = kap2;
end;

%
% Construct other endogenous variables
%

z1fp                = b1f*hfp^kap1*efp^zet1*l1fp;    % = phi1fp
z2fp                = b2f*hfp^kap2*efp^zet2*l2fp;    % = phi2fp
z1mp                = b1m*hmp^kap1*emp^zet1*l1mp;    % = phi1mp
z1fs                = b1f*hfs^kap1*efs^zet1*l1fs;    % = phi1fs
z2fs                = b2f*hfs^kap2*efs^zet2*l2fs;    % = phi2fs
z1ms                = b1m*hms^kap1*ems^zet1*l1ms;    % = phi1ms
z2ms                = b2m*hms^kap2*ems^zet2*l2ms;    % = phi2ms

phi1lfp             = z1fp/l1fp;
phi1hfp             = kap1*z1fp/hfp;
phi1efp             = zet1*z1fp/efp;
phi2lfp             = z2fp/l2fp;
phi2hfp             = kap2*z2fp/hfp;
phi2efp             = zet2*z2fp/efp;

phi1lmp             = z1mp/l1mp;
phi1hmp             = kap1*z1mp/hmp;
phi1emp             = zet1*z1mp/emp;

phi1lfs             = z1fs/l1fs;
phi1hfs             = kap1*z1fs/hfs;
phi1efs             = zet1*z1fs/efs;
phi2lfs             = z2fs/l2fs;
phi2hfs             = kap2*z2fs/hfs;
phi2efs             = zet2*z2fs/efs;

phi1lms             = z1ms/l1ms;
phi1hms             = kap1*z1ms/hms;
phi1ems             = zet1*z1ms/ems;
phi2lms             = z2ms/l2ms;
phi2hms             = kap2*z2ms/hms;
phi2ems             = zet2*z2ms/ems;

zbar                = nfs*z1fs+nms*z1ms+np*z1fp+np*z1mp;
kbar                = nfs*k1fs+nms*k1ms+np*k1p;

[F1,F1z,F1k]        = prodfn(zbar,kbar,theta1,mtech);
[F2p,F2zp,F2kp]     = prodfn(z2fp,k2p, theta2,htech);
[F2fs,F2zfs,F2kfs]  = prodfn(z2fs,k2fs,theta2,htech);
[F2ms,F2zms,F2kms]  = prodfn(z2ms,k2ms,theta2,htech);
[g1p,g1fp,g1mp]     = consfn(c1fp,c1mp,gpar);
[g2p,g2fp,g2mp]     = consfn(c2fp,c2mp,gpar);
c2fs                = F2fs;
c2ms                = F2ms;
c1p                 = c1fp+c1mp;
r                   = F1k;
w                   = F1z;
xk1p                = (gam+delk)*k1p;
xk1fs               = (gam+delk)*k1fs;
xk1ms               = (gam+delk)*k1ms;
xk2p                = (gam+delk)*k2p;
xk2fs               = (gam+delk)*k2fs;
xk2ms               = (gam+delk)*k2ms;
xhfp                = (gam+delh)*hfp;
xefp                = (gam+dele)*efp;
xhmp                = (gam+delh)*hmp;
xemp                = (gam+dele)*emp;
xhfs                = (gam+delh)*hfs;
xefs                = (gam+dele)*efs;
xhms                = (gam+delh)*hms;
xems                = (gam+dele)*ems;

if util==1; 
  [Ufp,Uf1p,Uf2p,Uflp] = util1(c1fp,c2fp,1-l1fp-l2fp,upar);
  [Ump,Um1p,Um2p,Umlp] = util1(c1mp,c2mp,1-l1mp,upar);
  [Ufs,Uf1s,Uf2s,Ufls] = util1(c1fs,c2fs,1-l1fs-l2fs,upar);
  [Ums,Um1s,Um2s,Umls] = util1(c1ms,c2ms,1-l1ms-l2ms,upar);
end;
if util==2;
  [Ufp,Uf1p,Uf2p,Uflp] = util2(c1fp,c2fp,1-l1fp-l2fp,upar);
  [Ump,Um1p,Um2p,Umlp] = util2(c1mp,c2mp,1-l1mp,upar);
  [Ufs,Uf1s,Uf2s,Ufls] = util2(c1fs,c2fs,1-l1fs-l2fs,upar);
  [Ums,Um1s,Um2s,Umls] = util2(c1ms,c2ms,1-l1ms-l2ms,upar);
end;
if util==3;
  [Ufp,Uf1p,Uf2p,Uflp] = util3(c1fp,c2fp,1-l1fp-l2fp,upar);
  [Ump,Um1p,Um2p,Umlp] = util3(c1mp,c2mp,1-l1mp,upar);
  [Ufs,Uf1s,Uf2s,Ufls] = util3(c1fs,c2fs,1-l1fs-l2fs,upar);
  [Ums,Um1s,Um2s,Umls] = util3(c1ms,c2ms,1-l1ms-l2ms,upar);
end;

%
% Steady state first-order conditions
%

f    = [Uflp*g1fp/Uf1p-w*(1-taulfp)*phi1lfp;
        Umlp*g1mp/Um1p-w*(1-taulmp)*phi1lmp;
        Uflp*g2fp/Uf2p-F2zp*phi2lfp;
        lam*Uf1p/g1fp-(1-lam)*Um1p/g1mp;
        lam*Uf2p/g2fp-(1-lam)*Um2p/g2mp;
        qk2/qk1-(F2kp*Uf2p/g2fp+qk2*(1-delk)*Uf1p/g1fp)/ ...
           (Uf1p/g1fp*((1-tauk)*r+tauk*delk+qk1*(1-delk)));
        g2p-F2p;
        qk1-beth*((1-tauk)*r+tauk*delk+qk1*(1-delk));
        (1-tauk)*r*k1p+tauk*delk*k1p+(1-taulfp)*w*z1fp+ ...
           (1-taulmp)*w*z1mp+(Tdp+Tp)/np-(c1p+qk1*xk1p+qk2*xk2p+ ...
           qh*xhfp+qe*xefp+qh*xhmp+qe*xemp);
        qh-beth*((1-delh)*qh+(1-taulfp)*w*(phi1hfp+(phi1lfp*phi2hfp)/phi2lfp));
        qe-beth*((1-dele)*qe+(1-taulfp)*w*(phi1efp+(phi1lfp*phi2efp)/phi2lfp));
        qh-beth*((1-delh)*qh+(1-taulmp)*w*phi1hmp);
        qe-beth*((1-dele)*qe+(1-taulmp)*w*phi1emp);
       
        Ufls/Uf1s-w*(1-taulfs)*phi1lfs;
        Ufls/Uf2s-F2zfs*phi2lfs;
        qk2/qk1-(F2kfs*Uf2s+qk2*(1-delk)*Uf1s)/ ...
           (Uf1s*((1-tauk)*r+tauk*delk+qk1*(1-delk)));
        (1-tauk)*r*k1fs+tauk*delk*k1fs+(1-taulfs)*w*z1fs+(Tdfs+Tfs)/nfs- ...
          (c1fs+qk1*xk1fs+qk2*xk2fs+qh*xhfs+qe*xefs);
        qh-beth*((1-delh)*qh+(1-taulfs)*w*(phi1hfs+(phi1lfs*phi2hfs)/phi2lfs));
        qh-beth*((1-dele)*qe+(1-taulfs)*w*(phi1efs+(phi1lfs*phi2efs)/phi2lfs));

        Umls/Um1s-w*(1-taulms)*phi1lms;
        Umls/Um2s-F2zms*phi2lms;
        qk2/qk1-(F2kms*Um2s+qk2*(1-delk)*Um1s)/ ...
           (Um1s*((1-tauk)*r+tauk*delk+qk1*(1-delk)));
        (1-tauk)*r*k1ms+tauk*delk*k1ms+(1-taulms)*w*z1ms+(Tdms+Tms)/nms- ...
           (c1ms+qk1*xk1ms+qk2*xk2ms+qh*xhms+qe*xems);
        qh-beth*((1-delh)*qh+(1-taulms)*w*(phi1hms+(phi1lms*phi2hms)/phi2lms));
        qh-beth*((1-dele)*qe+(1-taulms)*w*(phi1ems+(phi1lms*phi2ems)/phi2lms));

        nfs*(c1fs+qk1*xk1fs+qk2*xk2fs+qh*xhfs+qe*xefs)+ ...
           nms*(c1ms+qk1*xk1ms+qk2*xk2ms+qh*xhms+qe*xems)+ ...
           np*(c1p+qk1*xk1p+qk2*xk2p+qh*xhfp+qe*xefp+qh*xhmp+qe*xemp)-F1*(1-g);

        Tdp+Tdfs+Tdms+(taulms-taulmp)*np*w*z1mp-(taulfp-taulms)*np*w*z1fp- ...
          (taulfs-taulms)*nfs*w*z1fs;
           
        nfs*k1fs/(nfs*k1fs+nms*k1ms+np*k1p)-nfs/(nfs+nms+2*np);
        nms*k1ms/(nfs*k1fs+nms*k1ms+np*k1p)-nms/(nfs+nms+2*np);
  
        ((1-taulfp)*z1fp/l1fp*np+(1-taulfs)*z1fs/l1fs*nfs)/ ...
          ((1-taulmp)*z1mp/l1mp*np+(1-taulms)*z1ms/l1ms*nms)-relw];

