Interpreting Nonlinear Models with Stata's margins Command
Learn how to use Stata's margins command to transform complex nonlinear coefficients into interpretable probability changes using Average Marginal Effects (AME).
17 Jul 2026, 09:11 UTC

The Problem: Coefficients vs. Real-World Impact
In linear regression, a coefficient tells you exactly how much the dependent variable changes when a predictor increases by one unit. In nonlinear models—such as logistic (logit) or probit regressions—the coefficients represent changes in the link function (e.g., log-odds), which are not intuitively interpretable for most stakeholders. To understand the actual change in probability, you need marginal effects.
The margins command solves this by calculating the derivative of the predicted outcome with respect to a specific variable. This allows you to report a result like "a one-unit increase in education increases the probability of employment by 4 percentage points," rather than reporting a log-odds ratio.
Calculating Average Marginal Effects (AME)
Stata calculates marginal effects by taking the partial derivative of the model's prediction equation. Depending on your goal, you can calculate these effects at the sample means (Marginal Effects at the Mean) or average the effects across every individual in your dataset (Average Marginal Effects).
Worked Example: Logit Model Interpretation
Assume you are analyzing the probability of a loan approval (approved) based on credit score (score) and income (income). Use Stata version 17 or newer for full support of factor variables and interaction syntax.
* 1. Fit the nonlinear model
logit approved score income
* 2. Calculate the Average Marginal Effect (AME) for credit score
margins, dydx(score)
Command Breakdown:
logit: The estimation command.marginsonly works after commands that support thepredictfunction.dydx(score): Tells Stata to calculate the discrete change (derivative) in the outcome for a one-unit change inscore.
If you want to know the effect of credit score specifically for a person with average income, use the atmeans option:
margins, dydx(score) atmeans
Comparing AME vs. Predictive Margins
A common mistake is omitting the dydx() option. Without it, Stata produces predictive margins (the predicted probability) rather than marginal effects (the change in probability).
| Command | Result Type | Interpretation |
|---|---|---|
margins, at(score=700) |
Predictive Margin | "The probability of approval for someone with a score of 700 is 65%." |
margins, dydx(score) |
Marginal Effect | "A 1-point increase in score increases approval probability by 0.2%." |
Implementation Risks and Limitations
While powerful, margins is subject to specific technical constraints:
- Model Compatibility:
marginsrequires a smooth functional form. It will return an error if applied to non-smooth models, such as quantile regressions. - Standard Error Consistency: If your original regression used clustered standard errors (e.g.,
vce(cluster id)),marginsautomatically inherits this specification. However, if you manually adjust weights after the regression, the marginal effects may be biased. - Misspecification:
marginsis a post-estimation tool. It does not correct for omitted variable bias or incorrect functional forms; it simply interprets the model you have already built.
Verifying the Results
To verify that margins is calculating the effect correctly, you can manually approximate the derivative using the predict command. Run the following sequence in your Stata command window:
- Generate predicted probabilities for the current data:
predict p1, pr - Create a temporary variable that increases the predictor by a small amount:
gen score_plus = score + 0.01 - Use
predictagain based on the modified value (this requires manually adjusting the data and re-predicting):predict p2, pr - Calculate the average difference:
gen diff = (p2 - p1) / 0.01and thensummarize diff
The mean of diff should closely approximate the value reported by margins, dydx(score). If they diverge significantly, check if you have interaction terms in your model that were not specified in the margins command.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.