## Marginal Effect at Mean vs. Average Marginal Effect

In Stata version 11, the margins command was introduced for
computing marginal effects. When learning to use this, I encountered
an
article in the Stata Journal
that discussed the difference
between the **marginal effect at the mean** (MEM) and the
**average marginal effect** (AME).
This article provides a very good technical description
of these two methods. This tidbit briefly illustrates these
two different methods of computing marginal effects in a very
non-technical fashion.
This will be illustrated using the **nlsw** data file
using a logistic regression predicting whether a woman has
never been married (**never_married**) from whether she
is a college graduate (**collgrad**) and her
total work experience (**ttl_exp**). These variables
are shown below.

. use nlsw, clear (NLSW, 1988 extract) . summ never_married collgrad ttl_exp Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- never_marr~d | 2246 .1041852 .3055687 0 1 collgrad | 2246 .2368655 .4252538 0 1 ttl_exp | 2246 12.53498 4.610208 .1153846 28.88461

Let's now perform the logistic regression.

. logit never_married i.collgrad ttl_exp Iteration 0: log likelihood = -750.57436 Iteration 1: log likelihood = -729.66121 Iteration 2: log likelihood = -728.84823 Iteration 3: log likelihood = -728.84681 Iteration 4: log likelihood = -728.84681 Logistic regression Number of obs = 2246 LR chi2(2) = 43.46 Prob > chi2 = 0.0000 Log likelihood = -728.84681 Pseudo R2 = 0.0289 ------------------------------------------------------------------------------ never_marr~d | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- 1.collgrad | .5351603 .1485694 3.60 0.000 .2439696 .8263509 ttl_exp | .0835285 .0163158 5.12 0.000 .0515501 .1155069 _cons | -3.410128 .2401065 -14.20 0.000 -3.880728 -2.939528 ------------------------------------------------------------------------------

Let's describe the effect of **collgrad** by computing
the probability of never being married for those who
are not college graduates compared to those who are
college graduates. But, in doing so, let's hold
total work experience (**ttl_exp**) at its mean.
First, we compute the predicted logit for never being married
for those who did not graduate collage with an average amount
of work experience. This takes the logistic regression equation
from above and fills in 0 for **collgrad** and
12.534977 for **ttl_exp**.

. * Predicted logit(never married) for non-collgrad when experience is average . display -3.410128 + 0*.5351603 + 12.534977*.0835285 -2.3631002

We can then transform this into a predicted probability as shown below.

. * Predicted p(never married) for non-collgrad when experience is average . display exp(-2.3631002) / (1 + exp(-2.3631002)) .08603012

We repeat the steps from above for those who are college graduates

. * Predicted logit(never married) for collgrad when experience is average . display -3.410128 + 1*.5351603 + 12.534977*.0835285 -1.8279399 . . * Predicted p(never married) for collgrad when experience is average . display exp(-1.8279399) / (1 + exp(-1.8279399)) .13848387

Summarizing the above results, we find that for those who
are not college graduates the probability of never being married
is 0.086 and for those who are college graduates the probability of
never being married is 0.138. This was calculated by filling in
the average for total experience in the logistic regression model.
The difference between 0.086 and 0.138 is the
marginal effect of at the mean (MEM). It is the marginal effect
of **collgrad** when **ttl_exp** was held at the mean.

This same result can be obtained using the **margins** command
with the **atmeans** option, as shown below.

. margins collgrad , atmeans Adjusted predictions Number of obs = 2246 Model VCE : OIM Expression : Pr(never_married), predict() at : 0.collgrad = .7631345 (mean) 1.collgrad = .2368655 (mean) ttl_exp = 12.53498 (mean) ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- collgrad | 0 | .0860301 .006884 12.50 0.000 .0725377 .0995225 1 | .1384838 .0148692 9.31 0.000 .1093407 .167627 ------------------------------------------------------------------------------

Or, if you have used the **spostado** programs developed by J. Scott
Long, you have been computing MEM values. This is illustrated below
using the **prtab** command. (You can type **findit spostado**
to download this suite of commands.)

. logit never_married collgrad ttl_exp Iteration 0: log likelihood = -750.57436 Iteration 1: log likelihood = -729.66121 Iteration 2: log likelihood = -728.84823 Iteration 3: log likelihood = -728.84681 Iteration 4: log likelihood = -728.84681 Logistic regression Number of obs = 2246 LR chi2(2) = 43.46 Prob > chi2 = 0.0000 Log likelihood = -728.84681 Pseudo R2 = 0.0289 ------------------------------------------------------------------------------ never_marr~d | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- collgrad | .5351603 .1485694 3.60 0.000 .2439696 .8263509 ttl_exp | .0835285 .0163158 5.12 0.000 .0515501 .1155069 _cons | -3.410128 .2401065 -14.20 0.000 -3.880728 -2.939528 ------------------------------------------------------------------------------ . prtab collgrad logit: Predicted probabilities of positive outcome for never_married ----------------------------- college graduate | Prediction -----------------+----------- not college grad | 0.0860 college grad | 0.1385 ----------------------------- collgrad ttl_exp x= .23686554 12.534977

Let's fit this same model, but compute the
average marginal effect (AME) of **collgrad**.
First, we fit the model below.

. use nlsw, clear (NLSW, 1988 extract) . logit never_married collgrad ttl_exp Iteration 0: log likelihood = -750.57436 Iteration 1: log likelihood = -729.66121 Iteration 2: log likelihood = -728.84823 Iteration 3: log likelihood = -728.84681 Iteration 4: log likelihood = -728.84681 Logistic regression Number of obs = 2246 LR chi2(2) = 43.46 Prob > chi2 = 0.0000 Log likelihood = -728.84681 Pseudo R2 = 0.0289 ------------------------------------------------------------------------------ never_marr~d | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- collgrad | .5351603 .1485694 3.60 0.000 .2439696 .8263509 ttl_exp | .0835285 .0163158 5.12 0.000 .0515501 .1155069 _cons | -3.410128 .2401065 -14.20 0.000 -3.880728 -2.939528 ------------------------------------------------------------------------------

Now, let's compute the predicted probability of being
never married across all women. Let's do this twice,
the first time inserting the value of **0** for
**collgrad** and then again inserting the value of **1** for
**collgrad**. We leave **ttl_exp** as it is.

. replace collgrad = 0 (532 real changes made) . predict yhat0 (option pr assumed; Pr(never_married)) . replace collgrad = 1 (2246 real changes made) . predict yhat1 (option pr assumed; Pr(never_married))

**yhat0** contains the predicted value of
the model across all values of **ttl_exp** if
the woman was not a college graduate. Likewise,
**yhat1** contains the predicted value of
the model across all values of **ttl_exp** if
the woman was a college graduate.
Using the summarize command, we obtain the average
of these predicted values.

. summarize yhat0 yhat1 Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- yhat0 | 2246 .0907686 .0307244 .0322802 .269445 yhat1 | 2246 .1447145 .0458767 .0538943 .3864451

Using this method, the predicted probability of
being never married for non-college graduates is 0.0907
and for college graduates is 0.1447. This represents
the average marginal effect (AME) of **collgrad**
averaged across the values of **ttl_exp**.
If you use the **margins** command, this is
the value you would obtain. This is shown below.

. use nlsw, clear (NLSW, 1988 extract) . logit never_married i.collgrad ttl_exp Iteration 0: log likelihood = -750.57436 Iteration 1: log likelihood = -729.66121 Iteration 2: log likelihood = -728.84823 Iteration 3: log likelihood = -728.84681 Iteration 4: log likelihood = -728.84681 Logistic regression Number of obs = 2246 LR chi2(2) = 43.46 Prob > chi2 = 0.0000 Log likelihood = -728.84681 Pseudo R2 = 0.0289 ------------------------------------------------------------------------------ never_marr~d | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- 1.collgrad | .5351603 .1485694 3.60 0.000 .2439696 .8263509 ttl_exp | .0835285 .0163158 5.12 0.000 .0515501 .1155069 _cons | -3.410128 .2401065 -14.20 0.000 -3.880728 -2.939528 ------------------------------------------------------------------------------ . margins collgrad Predictive margins Number of obs = 2246 Model VCE : OIM Expression : Pr(never_married), predict() ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- collgrad | 0 | .0907686 .0069582 13.04 0.000 .0771308 .1044063 1 | .1447145 .0148072 9.77 0.000 .1156929 .1737362 ------------------------------------------------------------------------------

I hope that this provides a useful simple example for contrasting
the **marginal effect at the mean** (MEM) and the **average
marginal effect** (AME).

You can download the example data files from this tidbit
(as well as all of the other tidbits) as shown below.
These will download all of the example data files into
the current folder on your computer. (If you have done this
before, then you may need to specify **net get stowdata, replace**
to overwrite the existing files.

If you have thoughts on this Stata Tidbit of the Week, you can post a comment. You can also send me an email at MichaelNormanMitchell and then the at sign and gmail dot com. If you are receiving this tidbit via email, you can find the web version at http://www.michaelnormanmitchell.com/ .net from http://www.MichaelNormanMitchell.com/storage/stowdata net get stowdata

## Reader Comments (5)

Ah! I get it. Thanks.

Thank you! Excellent explanation. I'd like to add that with 'margins' we can compute MEM writing: margins collgrad ,atmeans. Am I wrong?

You are absolutely correct. This is a great observation. In fact, I have modified the tidbit to reflect this suggestion. Thanks for your comment!

If the goal of an analysis is to obtain an "adjusted prevalence" of a dichotomous outcome for various groups (say, counties or states), is this the same as the Average Marginal Effect?

Dear Nancy

I am not sure about the answer to your question, since the examples here involve comparisons among groups, whereas your example involves an overall estimate. I think this would be a great question to pose to the Statalist (see http://www.stata.com/statalist/) and I bet that someone will have a good answer for you.

Best regards,

Michael