function res = res_rbc_ed(Z,param);
%RES_RBC_ED    residual for neoclassical growth model with elastic labor
%              and distortions
%

%              Ellen R. McGrattan, 7-3-10
%              Revised, ERM, 12-5-13

%______________________________________________________________________________
%
% PARAMETERS

alpha      = param(1);
beta       = param(2);
delta      = param(3);
gn         = param(4);
gz         = param(5);
psi        = param(6);
theta      = param(7);
betg       = beta*(1+gz)^(-alpha);
thet1      = 1-theta;

%______________________________________________________________________________
%
% VARIABLES APPEARING IN RESIDUALS


kt         = exp(Z(1));
kt1        = exp(Z(2));
ct         = exp(Z(3));
kt2        = exp(Z(4));
ct1        = exp(Z(5));
zt         = exp(Z(6));
tauct      = Z(7);
taudt      = Z(8);
tauht      = Z(9);
taukt      = Z(10);
taupt      = Z(11);
tauxt      = Z(12);
gt         = exp(Z(13));
zt1        = exp(Z(14));
tauct1     = Z(15);
taudt1     = Z(16);
tauht1     = Z(17);
taukt1     = Z(18);
taupt1     = Z(19);
tauxt1     = Z(20);
gt1        = exp(Z(21));

yt         = ct+(1+gz)*(1+gn)*kt1-(1-delta)*kt+gt;
yt1        = ct1+(1+gz)*(1+gn)*kt2-(1-delta)*kt1+gt1;
ht         = (yt/(kt^theta))^(1/thet1) /zt;
ht1        = (yt1/(kt1^theta))^(1/thet1) /zt1;
uct        = ct^(-alpha)*(1-ht)^(psi*(1-alpha));
uct1       = ct1^(-alpha)*(1-ht1)^(psi*(1-alpha));
rt1        = theta*yt1/kt1;


res        = [(1-taudt)*(1+tauxt)-betg*(1-taudt1)*uct1*(1+(1-taupt1)* ...
                 (rt1-delta-taukt1)+(1-delta)*tauxt1)/uct;
              (1+tauct)*psi*ct/(1-ht)-(1-tauht)*(1-theta)*yt/ht];



