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.
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
- Estimate the model first, then run margins immediately.
- Use `margins, dydx(varlist)` for average marginal effects.
- For interactions, request margins at relevant values.
- 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.
1clear all2set obs 25003gen firm_id = ceil(_n/10)4gen year = 2012 + mod(_n,10)5gen education = 8 + floor(runiform()*10)6gen experience = 18 + floor(runiform()*20)78* Binary outcome example9gen employed = (runiform() < invlogit(-2 + 0.12*education + 0.04*experience))1011logit employed education experience i.year, vce(cluster firm_id)12margins, 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
-------------------------------------------------------------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.
1clear all2set obs 25003gen firm_id = ceil(_n/10)4gen year = 2012 + mod(_n,10)5gen education = 8 + floor(runiform()*10)6gen experience = 18 + floor(runiform()*20)78* Binary outcome example9gen employed = (runiform() < invlogit(-2 + 0.12*education + 0.04*experience))1011logit employed education experience i.year, vce(cluster firm_id)12margins, dydx(education experience)131415* ---- Section-specific continuation ----16logit employed c.education##c.experience i.year, vce(cluster firm_id)1718margins, dydx(education) at(experience=(20 30 40 50))19marginsplot, recast(line) noci ytitle("Marginal effect of education") xtitle("Experience")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
-------------------------------------------------------------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.
last estimates not found r(301);
clearmargins, dydx(education)logit employed education experiencemargins, dydx(education experience)1logit employed education experience i.year, vce(cluster firm_id)2estimates store logit_main3margins, dydx(education)Average marginal effects Expression: Pr(employed), predict() dy/dx wrt: education
Command Reference
margins
Stata docs โComputes adjusted predictions and marginal effects after estimation commands.
dydx(varlist)Marginal effects for selected predictorsat()Evaluates effects at specified covariate valuespredict()Chooses prediction scale for effectspostPosts margins results for further testingHow 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:
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.
Related Guides
- Logistic Regression in Stata: Marginal Effects That Actually Make Sense
- Interaction Effects in Stata: Factor Variables, margins, and Interpretation
- Stata predict: Postestimation Commands for Fitted Values, Residuals, and More
- Clustered Standard Errors in Stata: vce(cluster) Explained with Examples
- Explore the regression pillar page
- Open the full regression guide index
- Browse all Stata & R guides on the blog index
- Browse all Stata pillars
We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.