/* EVAL.G: evaluation of nonlinear regression model normal likelihood and derivatives (ignores sigma^2 parameter) Essentially does nonlinear regression for model y= exp(X'q) + epsilon By John Rust, Yale University, March, 1998 */ proc (4)=eval(dt,dloc,iloc,cloc,q,ll,dll,ls,lle,h,hll); local y,x,p,i; y=dt[.,dloc]; /* dependent variable in y */ x=dt[.,iloc']; /* independent variables in x */ ll=ll+sumc(-((y-exp(x*q))^2)/2); /* cumulate log-likelihood */ dll=dll+sumc((y-exp(x*q)).*exp(x*q).*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-exp(x*q)).*exp(x*q).*x,1); endif; /* cumulate hessian of likelihood */ i=1; do until i > rows(x); hll=hll-exp(2*x[i,.]*q)*x[i,.]'x[i,.]+ (y[i]-exp(x[i,.]*q))*exp(x[i,.]*q)*x[i,.]'x[i,.]; i=i+1; endo; skip: retp(ll,dll,h,hll); endp;