/* ** NLLS Estimation */ new ; @ LOADING DATA @ load dat[923,17] = wage2.txt ; @ OPEN OUTPUT FILE @ output file = nlls.out reset ; @ DEFINE VARIABLES @ wage = dat[.,1] ; hours = dat[.,2] ; iq = dat[.,3] ; kww = dat[.,4] ; educ = dat[.,5] ; exper = dat[.,6] ; tenure = dat[.,7] ; age = dat[.,8] ; married = dat[.,9] ; black = dat[.,10] ; south = dat[.,11] ; urban = dat[.,12] ; sibs = dat[.,13] ; brthord = dat[.,14] ; meduc = dat[.,15] ; feduc = dat[.,16] ; lwage = dat[.,17] ; @ DEFINE # of OBSERVATIONS @ tt = rows(dat) ; @ DEFINE MODEL ERROR TERM @ yy = wage; vny = {"wage"}; proc res(b) ; local e ; e = yy - exp(b[1] + b[2]*educ + b[3]*exper) ; retp( e ) ; endp ; @ DEFINE INITIAL VALUE @ bb = {0,0,0} ; library optmum; #include optmum.ext; optset ; proc f(b) ; local ltt ; ltt = res(b)'res(b) ; retp( ltt ) ; ENDP ; b0 = bb ; __title = "NLLS"; _opgtol = 1e-4; _opstmth = "bfgs, half"; __output = 0 ; {b,func,grad,retcode} = optmum(&f,b0) ; @ Covariance matrix @ hh = - gradp(&res,b); s2 = func/tt; cov = s2*invpd(hh'hh); se = sqrt(diag(cov)); r2 = 1- func/(yy'yy-tt*meanc(yy)^2); format /rd 10,4 ; "" ; "NLLS Estimation Result" ; "------------------------" ; " dependent variable: " $vny ; "" ; " R-square: " r2 ; "" ; " coeff. std. err. t-st " ; b~se~(b./se); "" ; output off ;