负二项模型中固定效应与边际效应问题:Stata操作疑惑咨询
Hey there! Let's break down your two questions about fixed-effects negative binomial regression in Stata step by step:
1. Calculating Impact Sizes for Dummy and Non-Dummy Independent Variables
Let's split this into practical, interpretable approaches based on variable type:
For Dummy Independent Variables (e.g., binary groups of执政时长)
Since dummy variables represent discrete jumps (from 0 to 1), you’ll want to measure the difference in predicted counts between groups, rather than a continuous slope. Here’s how to do it in Stata:
- First, run your core fixed-effects negative binomial model:
xtnbreg depvar dummy_var non_dummy_var i.id, fe - Use
marginsto get predicted counts for each dummy level, then compute their difference:
The second command returns the average change in expected counts when the dummy flips, accounting for individual fixed effects. Add// Get predicted mean counts for each dummy value margins dummy_var // Get the average difference when switching from 0 to 1 margins, dydx(dummy_var)atmeansif you want this calculation at the mean of all other covariates.
For Non-Dummy (Continuous) Independent Variables
Raw coefficients from xtnbreg, fe are on the log-count scale—they tell you how much the log of the expected count shifts per unit increase in the variable. To get a real-world impact size, use one of these two methods:
- Incidence Rate Ratios (IRRs): Exponentiate coefficients to get multiplicative effects. Run:
An IRR of 1.15 means a 1-unit increase in the variable links to a 15% rise in the expected count.xtnbreg depvar dummy_var non_dummy_var i.id, fe irr - Marginal Effects: Calculate the absolute change in expected counts per unit increase. Use:
This gives the average marginal effect (AME) across all observations. Since negative binomial models are non-linear, marginal effects vary by observation—AME is usually more informative than a single point estimate. Addmargins, dydx(non_dummy_var)atmeansto calculate the effect at the mean of all covariates.
2. Why Does margins, dydx(_all) Match Fixed-Effects Model Coefficients?
This confusion stems from how Stata calculates marginal effects for log-link models like negative binomial:
- Your model uses a log link:
log(μ_it) = X_itβ + α_i, whereμ_itis the expected count,X_itare covariates, andα_iare individual fixed effects. - The coefficient
βmeasures the change inlog(μ_it)per unit shift inX_it. The actual marginal effectdμ/dXequalsμ_it * β(from calculus: the derivative ofexp(Xβ + α_i)isexp(Xβ + α_i)*β = μ_it*β). - If
margins, dydx(_all)returns coefficients identical to your model, it’s almost certainly because the sample mean ofμ_it(expected count) is close to 1. Whenμ_it ≈ 1,μ_it*β ≈ β, so the marginal effect equals the raw coefficient. - To verify this, try calculating marginal effects at different covariate percentiles:
You’ll see varying marginal effects across these values, highlighting the model’s non-linear nature.margins, dydx(_all) at(non_dummy_var=(p25 p50 p75))
内容的提问来源于stack exchange,提问作者Alessio




