function Z = puttyclayss(paramss, z)

%paramss = [sigma delta gamma_a gamma_theta alpha beta M];

zz = zeros(paramss(7),1);
s1 = zeros(paramss(7),1);
s2 = zeros(paramss(7),1);

for i = 1:paramss(7)
    s1(i) = (1-normcdf(z(i)-paramss(1)))*(1-paramss(2))^(i-1)* paramss(6)^i*(paramss(3)*paramss(4)^(paramss(5)))^(i/(1-paramss(5)))*paramss(3)^i;
    s2(i) = (1-normcdf(z(i)))*(1-paramss(2))^(i-1)*paramss(6)^i*(paramss(3)*paramss(4)^(paramss(5)))^(i/(1-paramss(5)))*(paramss(3)*paramss(4))^(i/(1-paramss(5))); 
end;

 S1 = log(sum(s1));
 S2 = log(sum(s2));
 
 for i =1:paramss(7)
         zz(i) = z(i) - 1/paramss(1)*( log(1-paramss(5)) + S1 - S2 + 1/2*paramss(1)^2 + i* paramss(5)/(1-paramss(5)) * (log(paramss(3)) + log(paramss(4))));
    end;
        Z = zz;
end

