Have been using Stata to run negative binomial regressions in a replication. Not sure what is under the hood on how Stata does this, but wanted to know if there is an R function/package that does the same thing? The R will give me a better idea of how this works, since I can see the code.
Look into the glm.nb
function in the MASS
package. If you're interested in what's happening "under the hood," you can see the source code of the function by just entering its name at the command prompt.
If you're more comfortable using R, then that's probably the way to go; however, if you're interested in what's "under the hood" in Stata, you can always see what's going on in much the same way as in R by using
set trace on
to see what code is running (or download tr
from SSC) or using
viewsource xtnbreg.ado
to see the actual code that is run by xtnbreg
.
If you're interested in how Stata is calculating the results in xtnbreg
there is a detailed discussion of the likelihood function in the [XT] manual page 367-370 with references included.
© 2022 - 2024 — McMap. All rights reserved.