"NLREG.GPR: program to compute maximum likelihood estimates of nolinear least squares problem as a hint for Econ 551 midterm exam By John Rust, Yale University, March, 1997. "; /* STEP 1: Load in ASCII datasets and convert to GAUSS data sets with alternative-specific covariates for use in general form of multinomial logit model coded in EVAL.G. Note the 3 coefficients (const, slope_a and slope_b) are normalized to 0 for alternative 1. So estimate 3 coefficients for alternative 2.*/ load dat[]=dat1.asc; dat=reshape(dat,rows(dat)/2,2); y=dat[.,1]; x=ones(rows(dat),1)~dat[.,2]~dat[.,2]^2~dat[.,2]^3; dat=y~x; dat=saved(dat,"dat1","vnames"); let vnames=const b1 b2 b3 ; /* code to compute residuals from first stage NLS regression to uncover form of heteroscedasticity in second stage */ /* load beta; e=(y-exp(x*beta))^2; dat[.,1]=e; dat=saved(dat,"dat1","vnames"); */ load gam; load beta; iloc=seqa(2,1,4); cloc=0; dloc=1; q=zeros(4,1); /* q=beta; */ infile="dat1"; outfile="dat1.est"; qsav="beta"; dvar="y"; let ivar=beta0 beta1 beta2 beta3; /* Uncomment this line if you would like to run a derivative check, i.e. a comparison of numerical and analytical derivatives of the log-likelihood function */ /* call drvchk(dloc,iloc,cloc,q,infile,2000,outfile,qsav,&eval); call hesschk(dloc,iloc,cloc,q,infile,2000,outfile,qsav,&eval); */ /* Below is the main procedure that maximizes the likelihood function */ call max(dvar,dloc,ivar,iloc,cloc,q,infile,500,outfile,qsav,&eval);