Closed mikedenly closed 5 months ago
Hi @mikedenly ,
Glad you find the packages useful!
With the info you give, we can't rule out the possibility that the difference has nothing at all to do with marginaleffects
. To make sure this is a marginaleffects
issue, you would first need to ensure that standard errors around the simple coefficients are exactly identiical in R and Stata. That doesn't seem to be the case here:
Stata:
beertax | -.3472736 .1728049 -2.01
Estimate Std. Error z value
beertax -0.347274 0.174639 -1.98852
A small change in the variance-covariance matrix for the coefficients can have a big effect on the marginal effects standard errors, so it would be really important to match the basic estimates first.
I don't have access to Stata and I don't know what ppmlhdfe
is, so I can't really help figure out how it computes standard errors.
Thank you so much for your fast and helpful response, Vincent! @lrberge 's fixest::fepois()
replicates ppmlhdfe
in Stata (see confirmation here), so I perhaps should have directed the question to him given what you point out. ppmlhdfe
in Stata was put together by Sergio Correia (@sergiocorreia), Paulo Guimares (@pguimaraes99), and Tom Zylkin (@tomzylkin) (see their Stata Journal Article).
I'll be closing this now to keep the repo clean, because it does not appear (at first glance) to be a marginaleffects
bug or feature request.
If/when it becomes clear that this is a marginaleffects
problem, we can re-open the issue.
In any case, I am interested in the resolution, so feel free to keep discussing here if you want.
Hi Vincent (@vincentarelbundock),
As you can see from this other open issue that I started, both Laurent Bergé (@lrberge), the maintainer of fixest::fepois()
, and Alexander Fischer (@s3alfisc), the maintainer of pyfixest
, very kindly provided their expert advice on the standard error difference issue. I thus wanted to kindly ask if your conclusion remains the same regarding the massive differences in resulting marginal effect confidence intervals between the Stata and R
after fixest::fepois()
? On my side, I ended up submitting my paper to the journal with exponentiated coefficients, even though your work has clearly shown that they are less interpretable, because (i) exponentiated coefficients are consistent across software programs; and (ii) it was hard for me as a non-expert to take a stand one way or the other.
In any case, thank you so much again for your incredible work. It has really made a massive impact for the better on the social sciences and beyond.
Hi @mikedenly ,
Thanks for the kind words!
I must admit that I don't have a super strong intuition about what's going on here. If you want to diagnose, I'd probably start with:
vcov
argument of the avg_slopes()
function.I don't know if any of those paths would pan out, but that's where I would personally start.
Dear Vincent et al, I would like to kindly request your assistance with discerning why marginal effect confidence intervals and standard errors are different in Stata and R after estimating a fixed effects poisson pseudo-maximum likelihood (PMML) model. In R I am using
fixest::fepois()
andmarginaleffects::avg_slopes()
. In Stata I am usingppmlhdfe
andmargins, dydx(*)
. As one can see from my reproducible example below using theFatalities
dataset from R'sAER
package, everything is the same in the original models, and the marginal effect coefficients are the same, too. However, I can't obtain the same standard errors or confidence intervals for the marginal effects in R, even after trying different HC types and clustering options. This is odd because, in my reading of package documentation, both Stata and themarginaleffects
package inR
use the delta method to calculate standard errors.Here is the Stata output:
Here are my multiple attempts in R using
marginaleffects::avg_slopes()
:Does anyone know why this is happening and how Stata is obtaining the constant? I thought it should be absorbed the fixed effects. By the way, Vincent, your packages are incredible -- I teach them to all of my students. Thank you for everything and apologies if this should have gone on StackOverflow -- I wasn't sure about the correct forum for my question.
And here is
sessionInfo()
: