/* EVAL.G: evaluation of binary logit likelihood and derivatives By John Rust, Yale University, February, 1997 */ proc (6)=eval(dt,dloc,iloc,cloc,q,ll,dll,ls,lle,pnp,pcp,h,hll); local y,x,p; y=dt[.,dloc]; /* dependent variable in y */ 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 */ /* percent correctly predicted */ pcp=pcp+sumc((p.>=(.5)).*(y.==1)+(p.<(.5)).*(y.==0)); /* percent 'naively' predicted */ pnp=sumc(y.== 0)+pnp; /* 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); /* ohll=ohll-((x.*p)'((1-p).*x)); cumulate hessian of log-likelihood */ skip: retp(ll,dll,pnp,pcp,h,hll); endp;