# How can I compute the GMM in STATA without having any instrumental variables, just the underlying assumptions?

I am trying to find the coefficients of a linear model using the gauss-markov assumptions but since I am not experienced in Stata I do not know the code and was looking for the generic recipie: using gmm taking into account the assumptions that underlie the model (the point here is not to solve endogeneity, it is just to find the parameters).

You can "trick" Stata by using each covariate as an instrument for itself:

. sysuse auto
(1978 Automobile Data)

. regress price mpg weight

Source |       SS           df       MS      Number of obs   =        74
-------------+----------------------------------   F(2, 71)        =     14.74
Model |   186321280         2  93160639.9   Prob > F        =    0.0000
Residual |   448744116        71  6320339.67   R-squared       =    0.2934
Total |   635065396        73  8699525.97   Root MSE        =      2514

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -49.51222   86.15604    -0.57   0.567    -221.3025     122.278
weight |   1.746559   .6413538     2.72   0.008      .467736    3.025382
_cons |   1946.069    3597.05     0.54   0.590    -5226.245    9118.382
------------------------------------------------------------------------------

. gmm (price - {b1}*mpg - {b2}*weight - {b0}), instruments(mpg weight)

Step 1
Iteration 0:   GMM criterion Q(b) =   40528246
Iteration 1:   GMM criterion Q(b) =  1.537e-16
Iteration 2:   GMM criterion Q(b) =  2.125e-20

Step 2
Iteration 0:   GMM criterion Q(b) =  5.309e-27
Iteration 1:   GMM criterion Q(b) =  7.906e-32

note: model is exactly identified

GMM estimation

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

------------------------------------------------------------------------------
|               Robust
|      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
/b1 |  -49.51222   93.88752    -0.53   0.598    -233.5284    134.5039
/b2 |   1.746559   .7623472     2.29   0.022     .2523861    3.240732
/b0 |   1946.069   4129.762     0.47   0.637    -6148.117    10040.25
------------------------------------------------------------------------------
Instruments for equation 1: mpg weight _cons

. gmm (price - {xb: mpg weight _cons}), instruments(mpg weight)

Step 1
Iteration 0:   GMM criterion Q(b) =   40528246
Iteration 1:   GMM criterion Q(b) =  1.537e-16
Iteration 2:   GMM criterion Q(b) =  8.393e-21

Step 2
Iteration 0:   GMM criterion Q(b) =  1.292e-27
Iteration 1:   GMM criterion Q(b) =  1.065e-31

note: model is exactly identified

GMM estimation

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

------------------------------------------------------------------------------
|               Robust
|      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -49.51222   93.89379    -0.53   0.598    -233.5407    134.5162
weight |   1.746559   .7624037     2.29   0.022     .2522753    3.240843
_cons |   1946.069   4130.078     0.47   0.638    -6148.735    10040.87
------------------------------------------------------------------------------
Instruments for equation 1: mpg weight _cons


The second GMM is a slightly more compact way to write the first GMM.

• @RAGMS Did this clear things up? – Dimitriy V. Masterov Nov 2 '16 at 17:20
• More or less, when I use the Gauss Markov assumptions I have more moments conditions, the cov of the error terms are null, the variance of the error is constant and the the expected model is null. This last one yields the more moments the more variables we have. Am I wrong? – Ramiro Nov 4 '16 at 14:09
• Why don't you write out all the assumptions that you want to use in the original question and I will give it a whirl. – Dimitriy V. Masterov Nov 4 '16 at 15:17
• E(uiuj)=0, E(ui)=0, E(ui^2)=0, E(uixi)=0, – Ramiro Nov 4 '16 at 15:20
• I am not sure how to write the error covariance one. For everything else, you need to write your own evaluator to make things easy. – Dimitriy V. Masterov Nov 9 '16 at 1:34