/* EVALBLG.G: evaluation of binary logit likelihood and derivatives By John Rust, University of Maryland, November, 2005 */ proc (4)=evalblgfl(dt,dloc,iloc,cloc,q,ll,dll,ls,lle,h,hll); local ya,yb,xa,xb,pa,pb; ya=dt[.,1]; /* dependent variable in y */ yb=dt[.,2]; /* dependent variable in y */ xa=dt[.,3~4]; /* independent variables in x */ xb=dt[.,5~6]; /* independent variables in x */ pa=1/(1+exp(xa*q)); /* set choice probabilities */ pb=1/(1+exp(xb*q)); /* set choice probabilities */ ll=ll+sumc(ya.*ln(pa)+(1-ya).*ln(1-pa))+ sumc(yb.*ln(pb)+(1-yb).*ln(1-pb)); /* cumulate log-likeihood */ dll=dll+sumc((pa-ya).*xa)+ sumc((pb-yb).*xb); /* 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(((pa-ya).*xa+(pb-yb).*xb),1); /* endif; */ /* cumulate hessian of likelihood */ hll=hll-moment(sqrt(pa.*(1-pa)).*xa,1)- moment(sqrt(pb.*(1-pb)).*xb,1); /* ohll=ohll-((x.*p)'((1-p).*x)); cumulate hessian of log-likelihood */ skip: retp(ll,dll,h,hll); endp;