GMM Stata
GMM Stata
estimation in Stata 11
David M. Drukker
StataCorp
Encuentro de Usarios de Stata en Mexico 2010
1 / 26
Outline
1
A quick introduction to GMM
2
Using the gmm command
3
Bibliography
2 / 26
A quick introduction to GMM
What is GMM?
The generalize method of moments (GMM) is a general
framework for deriving estimators
Maximum likelihood (ML) is another general framework for
deriving estimators.
3 / 26
A quick introduction to GMM
GMM and ML
ML estimators use assumptions about the specic families of
distributions for the random variables to derive an objective
function
We maximize this objective function to select the parameters
that are most likely to have generated the observed data
GMM estimators use assumptions about the moments of the
random variables to derive an objective function
The assumed moments of the random variables are known as
the population moments
The data provide the sample moments
We minimize the objective function to select the parameters
that yield the smallest dierences between the population
moments and the sample moments
ML is a special case of GMM
4 / 26
A quick introduction to GMM
What is generalized about GMM?
For each assumed population moment, we obtain a population
moment condition
For each population moment condition, there is a sample
moment condition
In the method of moments (MM), we have the same number of
sample moment conditions as we have parameters
In the generalized method of moments (MM), we more sample
moment conditions than we have parameters
5 / 26
A quick introduction to GMM
Method of Moments (MM)
We estimate the mean of a distribution by the sample, the
variance by the sample variance, etc
We want to estimate = E[y]
The population moment condition is E[y] = 0
The sample moment condition is
(1/N)
N
i =1
y
i
= 0
Our estimator is obtained by solving the sample moment
condition for the parameter
Estimators that solve sample moment equations to produce
estimates are called method-of-moments (MM) estimators
This method dates back to Pearson (1895)
6 / 26
A quick introduction to GMM
Ordinary least squares (OLS) is an MM estimator
We know that OLS estimates the parameters of the condtional
expectation of y
i
= x
i
+
i
under the assumption that
E[|x] = 0
Standard probability theory implies that
E[|x] = 0 E[x] = 0
So the population moment conditions for OLS are
E[x(y x)] = 0
The corresponding sample moment condtions are
(1/N)
N
i =1
x
i
(y
i
x
i
) = 0
Solving for yields
OLS
=
_
N
i =1
x
i
x
i
_
1
N
i =1
x
i
y
i
7 / 26
A quick introduction to GMM
Generalized method-of-moments (GMM)
The MM only works when the number of moment conditions
equals the number of parameters to estimate
If there are more moment conditions than parameters, the
system of equations is algebraically over identied and cannot
be solved
Generalized method-of-moments (GMM) estimators choose the
estimates that minimize a quadratic form of the moment
conditions
GMM gets a close to solving the over-identied system as
possible
GMM reduces to MM when the number of parameters equals
the number of moment condtions
8 / 26
A quick introduction to GMM
Denition of GMM estimator
Our research question implies q population moment conditions
E[m(w
i
, )] = 0
m is q 1 vector of functions whose expected values are zero in
the population
w
i
is the data on person i
is k 1 vector of parmeters, k q
The sample moments that correspond to the population
moments are
m() = (1/N)
N
i =1
m(w
i
, )
When k < q, the GMM choses the parameters that are as close
as possible to solving the over-identied system of moment
equations
GMM
arg min
m()
Wm()
9 / 26
A quick introduction to GMM
Some properties of the GMM estimator
GMM
arg min
m()
Wm()
When k = q, the MM estimator solves m() exactly so
m()
Wm() = 0
W only aects the eciency of the GMM estimator
Setting W = I yields consistent, but inecent estimates
Setting W = Cov[m()]
1
yields an ecient GMM estimator
We can take multiple steps to get an ecient GMM estimator
1
Let W = I and get
GMM1
arg min
m()
m()
2
Use
GMM1
to get
W, which is an estimate of Cov[m()]
1
3
Get
GMM2
arg min
m()
Wm()
4
Repeat steps 2 and 3 using
GMM2
in place of
GMM1
10 / 26
Using the gmm command
The gmm command
The new command gmm estimates paramters by GMM
gmm is similar to nl, you specify the sample moment conditions
as substitutable expressions
Substitutable expressions enclose the model parameters in braces
{}
11 / 26
Using the gmm command
The syntax of gmm I
For many models, the population moment conditions have the
form
E[ze()] = 0
where z is a q 1 vector of instrumental variables and e() is a
scalar function of the data and the parameters
The corresponding syntax of gmm is
gmm (eb expression)
_
if
_
in
_
weight
,
instruments(instrument varlist)
_
options
1
+ legalwage
i
2
+
i
We want to model
E[crime|policepc, legalwage] =
0
+policepc
1
+legalwage
2
If E[|policepc, legalwage] = 0, the population moment
conditions
E
__
policepc
legalwage
_
_
=
_
0
0
_
hold
14 / 26
Using the gmm command
OLS by GMM I
. gmm (crime - policepc*{b1} - legalwage*{b2} - {b3}), ///
> instruments(policepc legalwage) nolog
Final GMM criterion Q(b) = 6.61e-32
GMM estimation
Number of parameters = 3
Number of moments = 3
Initial weight matrix: Unadjusted Number of obs = 10000
GMM weight matrix: Robust
Robust
Coef. Std. Err. z P>|z| [95% Conf. Interval]
/b1 -.4203287 .0053645 -78.35 0.000 -.4308431 -.4098144
/b2 -7.365905 .2411545 -30.54 0.000 -7.838559 -6.893251
/b3 27.75419 .0311028 892.34 0.000 27.69323 27.81515
Instruments for equation 1: policepc legalwage _cons
15 / 26
Using the gmm command
OLS by GMM I
. regress crime policepc legalwage, robust
Linear regression Number of obs = 10000
F( 2, 9997) = 4422.19
Prob > F = 0.0000
R-squared = 0.6092
Root MSE = 1.8032
Robust
crime Coef. Std. Err. t P>|t| [95% Conf. Interval]
policepc -.4203287 .0053653 -78.34 0.000 -.4308459 -.4098116
legalwage -7.365905 .2411907 -30.54 0.000 -7.838688 -6.893123
_cons 27.75419 .0311075 892.20 0.000 27.69321 27.81517
16 / 26
Using the gmm command
IV and 2SLS
For some variables, the assumption E[|x] = 0 is too strong and
we need to allow for E[|x] = 0
If we have q variables z for which E[|z] = 0 and the correlation
between z and x is suciently strong, we can estimate from
the population moment conditions
E[z(y x)] = 0
z are known as instrumental variables
If the number of variables in z and x is the same (q = k),
solving the the sample moment contions yield the MM estimator
known as the instrumental variables (IV) estimator
If there are more variables in z than in x (q > k) and we let
W =
_
N
i =1
z
i
z
i
_
1
in our GMM estimator, we obtain the
two-stage least-squares (2SLS) estimator
17 / 26
Using the gmm command
2SLS on crime data I
The assumption that E[|policepc] = 0 is false if communities
increase policepc in response an increase in crime (an increase
in
i
)
The variables arrestp and convictp are valid instruments, if
they measure some components of communities toughness-on
crime that are unrelated to but are related to policepc
We will continue to maintain that E[|legalwage] = 0
18 / 26
Using the gmm command
2SLS by GMM I
. gmm (crime - policepc*{b1} - legalwage*{b2} - {b3}), ///
> instruments(arrestp convictp legalwage ) nolog onestep
Final GMM criterion Q(b) = .001454
GMM estimation
Number of parameters = 3
Number of moments = 4
Initial weight matrix: Unadjusted Number of obs = 10000
Robust
Coef. Std. Err. z P>|z| [95% Conf. Interval]
/b1 -1.002431 .0455469 -22.01 0.000 -1.091701 -.9131606
/b2 -1.281091 .5890977 -2.17 0.030 -2.435702 -.1264811
/b3 30.0494 .1830541 164.16 0.000 29.69062 30.40818
Instruments for equation 1: arrestp convictp legalwage _cons
19 / 26
Using the gmm command
2SLS by GMM II
. ivregress 2sls crime legalwage (policepc = arrestp convictp) , robust
Instrumental variables (2SLS) regression Number of obs = 10000
Wald chi2(2) = 1891.83
Prob > chi2 = 0.0000
R-squared = .
Root MSE = 3.216
Robust
crime Coef. Std. Err. z P>|z| [95% Conf. Interval]
policepc -1.002431 .0455469 -22.01 0.000 -1.091701 -.9131606
legalwage -1.281091 .5890977 -2.17 0.030 -2.435702 -.1264811
_cons 30.0494 .1830541 164.16 0.000 29.69062 30.40818
Instrumented: policepc
Instruments: legalwage arrestp convictp
20 / 26
Using the gmm command
More complicated moment conditions
The structure of the moment conditions for some model is too
complicated to t into the interactive syntax used thus far
For example, Wooldridge (1999, 2002); Blundell, Grith, and
Windmeijer (2002) discuss estimating the xed-eects Poisson
model for panel data by GMM.
In the Poisson panel-data model we are modeling
E[y
it
|x
it
,
i
] = exp(x
it
+
i
)
Hausman, Hall, and Griliches (1984) derived a conditional
log-likelihood function when the outcome is assumed to come
from a Poisson distribution with mean exp(x
it
+
i
) and
i
is
an observed component that is correlated with the x
it
21 / 26
Using the gmm command
Wooldridge (1999) showed that you could estimate the
parameters of this model by solving the sample moment
equations
t
x
it
_
y
it
it
y
i
i
_
= 0
These moment conditions do not t into the interactive syntax
because the term
i
depends on the parameters
Need to use moment-evaluator program syntax
22 / 26
Using the gmm command
Moment-evaluator program syntax
An abreviated form of the syntax for gmm is
gmm moment progam
_
if
_
in
_
weight
,
equations(moment cond names)
parameters(parameter names)
_
instruments() options