You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

负二项模型中固定效应与边际效应问题:Stata操作疑惑咨询

Hey there! Let's break down your two questions about fixed-effects negative binomial regression in Stata step by step:

Answers to Your Fixed-Effects Negative Binomial Regression Questions

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 margins to get predicted counts for each dummy level, then compute their difference:
    // 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)
    
    The second command returns the average change in expected counts when the dummy flips, accounting for individual fixed effects. Add atmeans if 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:

  1. Incidence Rate Ratios (IRRs): Exponentiate coefficients to get multiplicative effects. Run:
    xtnbreg depvar dummy_var non_dummy_var i.id, fe irr
    
    An IRR of 1.15 means a 1-unit increase in the variable links to a 15% rise in the expected count.
  2. Marginal Effects: Calculate the absolute change in expected counts per unit increase. Use:
    margins, dydx(non_dummy_var)
    
    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. Add atmeans to 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 μ_it is the expected count, X_it are covariates, and α_i are individual fixed effects.
  • The coefficient β measures the change in log(μ_it) per unit shift in X_it. The actual marginal effect dμ/dX equals μ_it * β (from calculus: the derivative of exp(Xβ + α_i) is exp(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:
    margins, dydx(_all) at(non_dummy_var=(p25 p50 p75))
    
    You’ll see varying marginal effects across these values, highlighting the model’s non-linear nature.

内容的提问来源于stack exchange,提问作者Alessio

火山引擎 最新活动