/* EVAL.G: evaluation of nonlinear regression model with heteroscedastic normal errors by Full Information Maximum Likelihood (FIML) y= exp(X'beta) + epsilon var(epsilon|x)=exp(X'gam) q=(beta|gam); By John Rust, Yale University, March, 1998 */ proc (4)=eval(dt,dloc,iloc,cloc,q,ll,dll,ls,lle,h,hll); local i,y,x,p,b,g,hgg,hbg,hbb,dllb,dllg,ht; hbb=0; hgg=0; hbg=0; b=q[1:rows(q)/2]; /* beta: parameters for the conditional mean */ g=q[1+rows(q)/2:rows(q)]; /* gamma parameters for the conditional variance */ y=dt[.,dloc]; /* dependent variable in y */ x=dt[.,iloc']; /* independent variables in x */ /* cumulate log-likelihood */ ll=ll+sumc(-.5*ln(2*pi)-(.5)*x*g-((y-exp(x*b))^2)./(2*exp(x*g))); /* derivative of log-likelihood */ dllg=-x/2+(((y-exp(x*b))^2)./(2*exp(x*g))).*x; dllb=((y-exp(x*b))./exp(x*g)).*exp(x*b).*x; dll=dll+(sumc(dllb)|sumc(dllg)); 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 */ hbb=moment(dllb,1); hgg=moment(dllg,1); hbg=dllb'dllg; ht=(hbb~hbg)|(hbg'~hgg); h=h+ht; endif; /* cumulate hessian of likelihood */ hbb=0*hbb; hbg=0*hbg; hgg=0*hgg; i=1; do until i > rows(x); hbb=hbb+(y[i]-2*exp(x[i,.]*b))*exp(x[i,.]*(b-g))*x[i,.]'x[i,.]; hgg=hgg-(.5)*((y[i]-exp(x[i,.]*b))^2)*exp(-x[i,.]*g)*x[i,.]'x[i,.]; hbg=hbg-(y[i]-exp(x[i,.]*b))*exp(x[i,.]*(b-g))*x[i,.]'x[i,.]; i=i+1; endo; ht=(hbb~hbg)|(hbg'~hgg); hll=hll+ht; skip: retp(ll,dll,h,hll); endp;