--------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/baum/Documents/Courses 2009-2010/EC771 S2010/771reg.smcl
  log type:  smcl
 opened on:  22 Jan 2010, 09:41:44


. . // EC771reg cfb 0122 . // illustration of regression by OLS, MM, ML . . sysuse auto, clear (1978 Automobile Data)

. g gpm = 1 / mpg

. replace weight = weight / 1000 weight was int now float (74 real changes made)

. . // solution by OLS regression . regress gpm foreign weight

Source | SS df MS Number of obs = 74 -------------+------------------------------ F( 2, 71) = 113.97 Model | .009117618 2 .004558809 Prob > F = 0.0000 Residual | .00284001 71 .00004 R-squared = 0.7625 -------------+------------------------------ Adj R-squared = 0.7558 Total | .011957628 73 .000163803 Root MSE = .00632

------------------------------------------------------------------------------ gpm | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- foreign | .0062205 .0019974 3.11 0.003 .0022379 .0102032 weight | .016254 .0011827 13.74 0.000 .0138958 .0186122 _cons | -.0007348 .0040199 -0.18 0.855 -.0087504 .0072807 ------------------------------------------------------------------------------

. estat vce

Covariance matrix of coefficients of regress model

e(V) | foreign weight _cons -------------+------------------------------------ foreign | 3.990e-06 weight | 1.400e-06 1.399e-06 _cons | -5.415e-06 -4.640e-06 .00001616

. . // solution by method of moments . // GMM criterion will be minimized to zero as the model . // is exactly identified (3 moment conditions, 3 parameters) . gmm (gpm - {xb:foreign weight} - {b0}), /// > instruments(foreign weight) wmatrix(unadjusted) nolog

Final GMM criterion Q(b) = 4.70e-33

GMM estimation

Number of parameters = 3 Number of moments = 3 Initial weight matrix: Unadjusted Number of obs = 74 GMM weight matrix: Unadjusted

------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- /xb_foreign | .0062205 .0019565 3.18 0.001 .0023859 .0100552 /xb_weight | .016254 .0011585 14.03 0.000 .0139835 .0185245 /b0 | -.0007348 .0039376 -0.19 0.852 -.0084524 .0069827 ------------------------------------------------------------------------------ Instruments for equation 1: foreign weight _cons

. // note that the VCE estimates are large-sample . // and thus do not agree with those of OLS . estat vce

Covariance matrix of coefficients of gmm model

| xb_foreign | xb_weight | b0 e(V) | _cons | _cons | _cons -------------+------------+------------+------------ xb_foreign | | | _cons | 3.828e-06 | | -------------+------------+------------+------------ xb_weight | | | _cons | 1.344e-06 | 1.342e-06 | -------------+------------+------------+------------ b0 | | | _cons | -5.195e-06 | -4.452e-06 | .0000155

. . // solution by maximum likelihood . // For linear regression assuming normally distributed errors, . // ln L = sum [ ln phi( (y_i - x_i b) / sigma ) - ln sigma ] . // where phi( ) is the density of N(0, 1) . // The three-parameter form of Stata's normalden(x, m, s) function . // returns [ phi((x-m)/s) / s ], so we may call it directly . // to evaluate the likelihood of each observation . program drop _all

. program mynormalreg_lf 1. version 11 2. args lnf mu sigma 3. quietly replace `lnf' = /// > ln(normalden( $ML_y1, `mu', `sigma' ) ) 4. end

. . ml model lf mynormalreg_lf (gpm = foreign weight) /sigma

. ml maximize, nolog initial: log likelihood = -<inf> (could not be evaluated) feasible: log likelihood = -46.676799 rescale: log likelihood = 168.74536 rescale eq: log likelihood = 192.31154

Number of obs = 74 Wald chi2(2) = 237.57 Log likelihood = 271.21503 Prob > chi2 = 0.0000

------------------------------------------------------------------------------ gpm | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | foreign | .0062205 .0019565 3.18 0.001 .0023859 .0100552 weight | .016254 .0011585 14.03 0.000 .0139835 .0185245 _cons | -.0007348 .0039376 -0.19 0.852 -.0084524 .0069827 -------------+---------------------------------------------------------------- sigma | _cons | .006195 .0005092 12.17 0.000 .005197 .0071931 ------------------------------------------------------------------------------

. // estimate of /sigma may be compared with RMS Error from OLS . // but degrees of freedom differ . // note that the VCE estimates, based on /sigma, are large-sample . estat vce

Covariance matrix of coefficients of ml model

| eq1 | sigma e(V) | foreign weight _cons | _cons -------------+------------------------------------+------------ eq1 | | foreign | 3.828e-06 | weight | 1.344e-06 1.342e-06 | _cons | -5.195e-06 -4.452e-06 .0000155 | -------------+------------------------------------+------------ sigma | | _cons | -4.394e-14 -4.034e-14 6.192e-14 | 2.593e-07

. . log close name: <unnamed> log: /Users/baum/Documents/Courses 2009-2010/EC771 S2010/771reg.smcl log type: smcl closed on: 22 Jan 2010, 09:41:44 --------------------------------------------------------------------------------------------------------------