/* LOG_NLS.G: nonlinear least squares estimation of binary logit model By John Rust, Yale University, April, 1998 */ proc (4)=log_nls(dt,dloc,iloc,cloc,q,ll,dll,ls,lle,h,hll); local y,x,p,i,unos; y=dt[.,dloc]; /* dependent variable in y */ y=.not(y); /* reverse entries so 1-phi(xq)=1/(1+exp(xq)) */ x=dt[.,iloc']; /* independent variables in x */ p=1/(1+exp(x*q)); ll=ll+sumc(-(y-p)^2)/2; /* cumulate log-likelihood */ dll=dll-sumc((y-p).*p.*(1-p).*x); /* derivative of log-likelihood */ if ls > 0; goto skip; endif; /* don't compute hessian in linesearch */ if lle == -1; /* last likelihood evaluation iteration */ /* cumulate outer product of 1st derivs */ h=h+moment((y-p).*p.*(1-p).*x,1); endif; /* cumulate hessian of likelihood */ i=1; do until i > rows(x); hll=hll-((p[i]*(1-p[i]))^2)*x[i,.]'x[i,.]+ (y[i]-p[i])*p[i]*(1-p[i])*(1-2*p[i]).*x[i,.]'x[i,.]; i=i+1; endo; skip: retp(ll,dll,h,hll); endp;