ME at the Margins: Average Marginal Effects, Marginal Effects at the Mean, and Stata’s margins command

Seems that my students and I are not the only ones who are occasionally baffled by Stata’s margins command, which does all sorts of amazing things. Margins is incredibly powerful, and the accompanying marginsplot command almost always does just the right thing. These commands come with excellent documentation, but at a mere 58 pages (not counting the remarks on margins post-estimation), the manual entry on margins alone is a little overwhelming, and there are just too many options.

There are two separate issues in particular that seem to confuse a lot of people (see this discussion on statalist on the then new margins command).

Marginal Effects at the Mean vs Average Marginal Effects

The first is that in the past when studying the implications from nonlinear (i.e. logit) models, many people including me used to analyse “marginal effects at the mean“. In short, this boils down to holding most independent variables constant at their grand means/modes while plugging a range of hopefully relevant values for one or two focal variables into the equation. This approach, which was pioneered by J. Scott Long, is easier to understand than to explain and greatly aids the interpretation of non-linear models.

Margins can (amongst many other things) estimate marginal effects at the mean. But unfortunately, this can result in very unrealistic scenarios if your independent variables are highly correlated (think of holding age constant at its mean while varying pensioner/non-pensioner status).

ME at the Margins: Average Marginal Effects, Marginal Effects at the Mean, and Stata's margins command 1

Therefore, looking at “average marginal effects” often makes more sense. These are calculated by varying the focal variable while holding everything else at their variables. This is was the margins command does by default. Michael Norman Mitchell has a post (since removed, but thankfully preserved by the internet archive) that clearly illustrates the differences between the two approaches to the estimation of margins. If you are ready for a somewhat deeper dive, Richard Williams’ 2012 article on Using the margins command to estimate and interpret adjusted predictions and marginal effects is a modern classic and a masterclass in didactics, free for you to read at this URL. Moreover, there is an older article by Tamás Bartus on his margeff command that is also quite instructive.

One problem with understanding what margins (the thing) and margins (the command) are about is that the terminology varies wildly within and across disciplines. In this respect, I find Williams’ definitions and explanations particularly helpful.

Dubious Confidence Intervals

But one problem remains: margins uses a normal approximation for calculating confidence intervals. As a result, after estimating a model for categorical dependent variables, you might end up with a CI for your margins that includes zero, which obviously does not make much sense. Roger Newson seems to know how to get around this issue. So far, I haven’t used his approach, but it looks plausible enough.


Margins and the marginsplot command are incredibly powerful tools. I take it that they have been partially ported to R, but I do not know if these packages are as good as the original. See Will’s extensive comment below – again, this looks very interesting.

My students have been conditioned (geddit? geddit) to resort to margins whenever we encounter interactions and nonlinearities. If you want to get an idea what margins can do for you, there is a lot of tutorials on the internet to work through, and the Stata blog is not the worst place to start.

16 thoughts on “ME at the Margins: Average Marginal Effects, Marginal Effects at the Mean, and Stata’s margins command”

  1. “I take it that they have been partially ported to R”

    They have been extensively ported to R in the marginaleffects package (a successor to the margins package), with uncertainty available from delta method, (cluster) robust, simulation and bootstrap methods. The package comes with an online book full of case studies and explanations. Available here:


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.