Regression
2026-02-2314 min read

Stata margins: Complete Guide to Marginal Effects with Interpretation

AME, MEM, MER โ€” all demystified. margins after OLS, logit, probit, interactions, continuous variables, and marginsplot customization.

Sytra Team
Research Engineering Team, Sytra AI

Your coefficients are statistically significant, but you still cannot answer the practical question your coauthor asked.

You will convert raw model output into interpretable marginal effects that match substantive research claims.

All examples tested in Stata 18 SE. Compatible with Stata 15+.


Quick Answer

  1. Estimate the model first, then run margins immediately.
  2. Use `margins, dydx(varlist)` for average marginal effects.
  3. For interactions, request margins at relevant values.
  4. Plot effects with marginsplot for transparent communication.

Translate Model Coefficients into Substantive Effects

Compute average marginal effects after logit

In nonlinear models, coefficients are not direct probability changes. Marginal effects map estimates to interpretable probability scale.

Average marginal effects summarize impacts across the observed sample, improving external interpretability.

If you are extending this pipeline, also review How to Merge Datasets in Stata and How to Structure a Stata Project.

margins-ame.do
stata
1clear all
2set obs 2500
3gen firm_id = ceil(_n/10)
4gen year = 2012 + mod(_n,10)
5gen education = 8 + floor(runiform()*10)
6gen experience = 18 + floor(runiform()*20)
7
8* Binary outcome example
9gen employed = (runiform() < invlogit(-2 + 0.12*education + 0.04*experience))
10
11logit employed education experience i.year, vce(cluster firm_id)
12margins, dydx(education experience)
. margins, dydx(education experience)
Average marginal effects                        Number of obs = 2,500
Model VCE: Robust
Expression: Pr(employed), predict()
dy/dx wrt:  education experience
-------------------------------------------------------------
             |            Delta-method
             |      dy/dx   std. err.      z    P>|z|
-------------+-----------------------------------------
   education |   .0209143   .0021045     9.94   0.000
  experience |   .0068817   .0010992     6.26   0.000
-------------------------------------------------------------
๐Ÿ’กAME is often publication default
Average marginal effects are generally easier to explain and compare across studies than raw logit coefficients.

Interpret interaction effects with marginsplot

Interaction coefficients in nonlinear models are not equal to interaction effects on probabilities. margins handles this correctly.

Evaluate effects at meaningful covariate values, then plot to detect nonlinearity and crossover patterns.

margins-interactions.do
stata
1clear all
2set obs 2500
3gen firm_id = ceil(_n/10)
4gen year = 2012 + mod(_n,10)
5gen education = 8 + floor(runiform()*10)
6gen experience = 18 + floor(runiform()*20)
7
8* Binary outcome example
9gen employed = (runiform() < invlogit(-2 + 0.12*education + 0.04*experience))
10
11logit employed education experience i.year, vce(cluster firm_id)
12margins, dydx(education experience)
13
14
15* ---- Section-specific continuation ----
16logit employed c.education##c.experience i.year, vce(cluster firm_id)
17
18margins, dydx(education) at(experience=(20 30 40 50))
19marginsplot, recast(line) noci ytitle("Marginal effect of education") xtitle("Experience")
. margins, dydx(education) at(experience=(20 30 40 50))
Conditional marginal effects                    Number of obs = 2,500
Expression: Pr(employed), predict()
dy/dx wrt: education
1._at: experience = 20
2._at: experience = 30
3._at: experience = 40
4._at: experience = 50
-------------------------------------------------------------
             |      dy/dx   std. err.      z    P>|z|
-------------+-----------------------------------------
1._at        |   .0281021   .0031140     9.02   0.000
2._at        |   .0229034   .0026127     8.76   0.000
3._at        |   .0184042   .0022249     8.27   0.000
4._at        |   .0142951   .0020420     7.00   0.000
-------------------------------------------------------------
๐Ÿ‘Do not interpret interaction coefficient alone
The coefficient on education#experience is not the same object as the probability-scale interaction effect.

Common Errors and Fixes

"last estimates not found"

margins was run without an active estimation result in memory.

Run the estimation command immediately before margins and avoid commands that clear e() results.

. clear
last estimates not found
r(301);
This causes the error
wrong-way.do
stata
clear
margins, dydx(education)
This is the fix
right-way.do
stata
logit employed education experience
margins, dydx(education experience)
error-fix.do
stata
1logit employed education experience i.year, vce(cluster firm_id)
2estimates store logit_main
3margins, dydx(education)
. margins, dydx(education)
Average marginal effects
Expression: Pr(employed), predict()
dy/dx wrt: education

Command Reference

Computes adjusted predictions and marginal effects after estimation commands.

margins [, dydx(varlist) at(var=(values)) predict()]
dydx(varlist)Marginal effects for selected predictors
at()Evaluates effects at specified covariate values
predict()Chooses prediction scale for effects
postPosts margins results for further testing

How Sytra Handles This

Sytra can produce margins and marginsplot code tied to your model specification and output interpretation notes for reporting.

A direct natural-language prompt for this exact workflow:

sytra-prompt.txt
bash
Estimate a clustered logit model for employed on education and experience, compute AMEs, evaluate education effects at experience levels 20 30 40 50, and generate marginsplot-ready output.

Sytra catches these errors before you run.

Sytra can produce margins and marginsplot code tied to your model specification and output interpretation notes for reporting.

Join the Waitlist โ†’

FAQ

What is the difference between odds ratios and marginal effects?

Odds ratios are multiplicative effects on odds, while marginal effects report approximate changes in predicted probability, which are often easier to communicate.

Should I report dydx atmeans or average marginal effects?

Average marginal effects are generally preferred because they average individual-level effects and avoid dependence on one synthetic profile.

Can I use margins after linear regression?

Yes. margins is useful after linear and nonlinear models, especially with interactions or factor variables where direct coefficient interpretation is harder.


Written by Sytra Team
Research Engineering Team, Sytra AI

We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.

#Stata#margins#Marginal Effects#Econometrics

Enjoyed this article?