/* LOG_MLE.G: maximum likelihood estimation of binary logit model By John Rust, Yale University April, 1998 */ proc (4)=log_mle(dt,dloc,iloc,cloc,q,ll,dll,ls,lle,h,hll); local y,x,p; y=dt[.,dloc]; /* dependent variable in y */ y=.not(y); /* reverse y's so that Pr{y=1|x}=exp(xq)/(1+exp(xq)) */ x=dt[.,iloc']; /* independent variables in x */ p=1/(1+exp(x*q)); /* set choice probabilities */ ll=ll+sumc(y.*ln(p)+(1-y).*ln(1-p)); /* cumulate log-likeihood */ dll=dll+sumc((p-y).*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((p-y).*x,1); endif; /* cumulate hessian of likelihood */ hll=hll-moment(sqrt(p.*(1-p)).*x,1); skip: retp(ll,dll,h,hll); endp;