/* PRB_MLE.G: full information maximum likelihood estimation of binary probit model By John Rust, Yale University, March, 1998 */ proc (4)=prb_mle(dt,dloc,iloc,cloc,q,ll,dll,ls,lle,h,hll); local y,x,p,i,cn,wts; cn=1/sqrt(2*pi); y=dt[.,dloc]; /* dependent variable in y */ x=dt[.,iloc']; /* independent variables in x */ p=cdfn(x*q); wts=p.*(1-p); ll=ll+sumc(y.*ln(p)+(1-y).*ln(1-p)); /* cumulate log-likelihood */ dll=dll+cn*sumc((y-p).*exp(-((x*q)^2)/2).*x./wts); /* 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(cn*(y-p).*exp(-((x*q)^2)/2).*x./wts,1); endif; /* cumulate hessian of likelihood */ i=1; do until i > rows(x); hll=hll-cn*cn*exp(-(x[i,.]*q)^2)*x[i,.]'x[i,.]/wts[i]- cn*(y[i]-p[i])*(x[i,.]*q)* exp(-((x[i,.]*q)^2)/2)*x[i,.]'x[i,.]/wts[i]; i=i+1; endo; skip: retp(ll,dll,h,hll); endp;