/* EVAL.G: Feasible GLS evaluation of nonlinear regression model y= exp(X'q) + epsilon Using first stage estimates of residual variance function for weights 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,wt; y=dt[.,dloc]; /* dependent variable in y */ x=dt[.,iloc']; /* independent variables in x */ wt=exp(-x*gam); ll=ll+sumc(-((y-exp(x*q))^2).*wt/2); /* cumulate log-likelihood */ dll=dll+sumc((y-exp(x*q)).*wt.*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)).*wt.*exp(x*q).*x,1); endif; /* cumulate hessian of likelihood */ i=1; do until i > rows(x); hll=hll-exp(2*x[i,.]*q)*wt[i]*x[i,.]'x[i,.]+ (y[i]-exp(x[i,.]*q))*wt[i]*exp(x[i,.]*q)*x[i,.]'x[i,.]; i=i+1; endo; skip: retp(ll,dll,h,hll); endp;