Stata: Data Analysis and Statistical Software
   >> Home >> Products >> Capabilities >> Marginal analysis
order stataorder stata

Marginal means, adjusted predictions, and marginal effects

Stata does margins. Does estimated marginal means. Does least-squares means. Does average and conditional marginal/partial effects, as derivatives or elasticities. Does average and conditional adjusted predictions. Does predictive margins. Does contrasts and pairwise comparisons of margins. Does more. Margins are statistics calculated from predictions of a previously fit model at fixed values of some covariates and averaging or otherwise integrating over the remaining covariates.

If that sounds overly technical, try this. margins answers the question, “What does my model have to say about such-and-such a group or such-and-such a person”, where such-and-such might be:

  • my estimation sample or another sample
  • a sample with the values of some covariates fixed
  • a sample evaluated at each level of a treatment
  • a population represented by a complex survey sample
  • someone who looks like the fifth person in my sample
  • someone who looks like the mean of the covariates in my sample
  • someone who looks like the median of the covariates in my sample
  • someone who looks like the 25th percentile of the covariates in my sample
  • someone who looks like some other statistics of the covariates in my sample
  • a standardized population
  • a balanced experimental design
  • any combination of the above
  • any comparison of the above

It answers these questions either conditionally—based on fixed values of covariates—or averaged over the observations in a sample. Any sample.

It answers these questions about any prediction or any other response you can calculate as a function of your estimated parameters—linear responses, probabilities, hazards, survival times, odds ratios, risk differences, etc.

It answers these questions in terms of the response given covariate levels or in terms of the change in the response for a change in levels, a.k.a. marginal effects.

It answers these questions providing standard errors, test statistics, and confidence intervals and those statistics can take the covariates as given or adjust for sampling, a.k.a predictive margins and survey statistics.

marginsplot can graph any of these margins or comparisons of margins.

Say that we are interested in the outcome y based on a person’s gender and packages of cigarettes smoked per day. Using Stata’s factor-variable notation, we can fit a logistic regression by typing

The interaction between sex and smokes makes interpretation difficult. We can use margins to decipher their effects:

We obtain predictive margins. If the distribution of cigarettes smoked remained the same in the population, but everyone was male, we would expect about 45% to have a positive outcome for y. If everyone were female; 55%. If instead the distribution of males and females were as observed but no one smoked, we would expect about 39% to have a positive outcome.

Is there a significant difference in the probability of a positive outcome between males and females? We can run tests after margins to find out:

We find evidence at the 5% significance level that the predictive margins differ for males and females.

How do sex and the number of cigarettes smoked interact? After fitting our logistic regression, we can obtain predictive margins for each of the levels in the interaction of these variables:

An easy way to look at this interaction is to graph it using the marginsplot command.

. marginsplot

Let’s see an example of marginal effects. Because of Stata’s factor-variable features, we can get average partial and marginal effects for age even when age enters as a polynomial:

We are using different data than before. The probability that a person is in a union increases by 0.0015 as age increases by one year. By default, margins reports average marginal (partial) effects, which means effects are calculated for each observation in the data and then averaged.

Alternatively, if we wanted effects at the average of the covariates, we could type

. margins, dydx(age) atmeans

Stata’s margins command includes options to control whether the standard errors reflect just the sampling variation of the estimated coefficients or whether they also reflect the sampling variation of the estimation sample. In the latter case, margins can account for complex survey sampling including weights, sampling units, pre- and poststratification, and subpopulations.

margins works after EVERY Stata estimation command except exact logistic and exact Poisson; alternative-specific conditional logistic, alternative-specific multinomial probit, and alternative-specific rank-ordered probit; nested logit; generalized method of moments; structural vector autoregressive models; state space; unobserved components; and structural equation models.

Bookmark and Share 
Stata 12
Overview: Why use Stata?
Stata/MP
Capabilities
Overview
Sample session
User-written commands
New in Stata 12
Supported platforms
Which Stata?
Technical support
User comments
Like us on Facebook Follow us on Twitter Follow us on LinkedIn Google+ Watch us on YouTube
Follow us
© Copyright 1996–2013 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index   |   View mobile site