1

I have estimated the following negative binomial regression model with group fixed effects in Stata. The data are time series cross sectional. The panelvar is group and the timevar is time.

tsset group time
xtnbreg y x1 x2 x3 + x4 + x5, fe

I want to replicate these findings in R. To do this, I have tried these 4 models:

nb1 <- femlm(y ~ x1 + x2 + x3 + x4 + x5 | group, panel.id = ~group + time, family = "negbin", mydata)
nb2 <- fenegbin(y ~ x1 + x2 + x3 + x4 + x5 | group, panel.id = ~group + time, mydata)
nb3 <- glm.nb(y ~ x1 + x2 + x3 + x4 + x5 + factor(group), data=mydata)
nb4 <- glmmadmb(y ~ x1 + x2 + x3 + x4 + x5 + factor(group), data = mydata, family="nbinom")

The results produced by nb1-4 are all identical, but different from the results produced by xtnbreg in Stata. The coefficients, standard errors, and p-values are all substantively different.

I have tried replicating a standard negative binomial regression in Stata and R and have been able to do so successfully.

Does anyone have any idea what's going on here? I have reviewed related posts on this forum (such as this one: is there an R function for Stata's xtnbreg?) and have not found any answers.

Gabriella
  • 31
  • 4
  • 1
    Is there any chance we can have a [mcve]? Looking at https://www.stata-press.com/manuals/errata/stata6/i/xtnbreg.pdf, it says "a conditional likelihood is used in which the dispersion parameter drops out of the estimation". See also https://statisticalhorizons.com/fe-nbreg .... `?fixest::femlm` also strongly suggests that it is is using *unconditional* ML ... – Ben Bolker Jun 16 '21 at 22:24
  • 1
    If you want to know "what is the difference between conditional and unconditional ML in this context and why does it matter?" that might be a question for [CrossValidated](https://stats.stackexchange.com) – Ben Bolker Jun 16 '21 at 22:28
  • 1
    More questions: what does `xtnbreg` do with / assume about the time variable? – Ben Bolker Jun 16 '21 at 22:30
  • Thank you! I had not noticed this difference between the two commands. I will look into this further and will follow up if it ends up being the source of the issue. – Gabriella Jun 16 '21 at 22:31
  • 1
    If you've solved your own problem, you should post your answer as an *answer*, rather than as an edit to your question (self-answering is encouraged on Stack Overflow - there may be a waiting period before you can self-answer as a new user, but I suspect it's elapsed already) – Ben Bolker Jun 17 '21 at 00:31

1 Answers1

1

SOLVED (mostly): The R code that reproduces the results generated by xtnbreg, fe in Stata:

nb5 <- pglm(y ~ x1 + x2 + x3 + x4 + x5 ,family = negbin, data = mydata, effect = "individual", model="within", index = "group")

I found the solution on RPubs: https://rpubs.com/cuborican/xtpoisson. I still do not know why this works, only that it does. I suspect that Ben is correct and it has something to do with estimating conditional vs unconditional ML. If anyone knows for sure, please share.

Gabriella
  • 31
  • 4