lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
377 stars 59 forks source link

Added support methods for emmeans #454

Closed rvlenth closed 5 months ago

rvlenth commented 10 months ago

Following-up on an emmeans user's suggestion. I have put together some support methods for the emmeans package. With it set up as provided, these methods will be registered when fixest is loaded, provided that emmeans is installed.

The provided example uses the AER package. I just didn't want to do an example with the iris data, as it is so far afield of the kinds of applications we would want with fixest. I think your package would benefit from having at least a somewhat realistic econometric example dataset built-in.

There are some important notes in the ROxygen comments. Only the variables in the main model are considered in the reference grid created by emmeans -- no fixed effects nor instrumental variables. Your vcov and other optional arguments to vcov() are supported via optional arguments to emmeans(). And an important consideration: while the estimates of marginal means are correct, their standard errors and CIs are incorrect when we have fixed effects, because the EMMs involve the intercept for which we don't have variances and covariances; however, contrasts among EMMs are fine because the intercept is zeroed-out.

lrberge commented 8 months ago

Hi, this is a very neat PR, thanks for the effort. I'll try to review it in the coming weeks.

ocolluphid commented 6 months ago

+1 on getting this PR approved, would be useful to output pairwise contrasts using fixest models with emmeans (and with clustered SEs) :)

lrberge commented 5 months ago

Hi, I finally accepted the fact that I will never have the time to thoroughly review the PR so I just merged it as it is, and I didn't check it worked. Given your credentials I think I'm safe by assuming that it just works :-) Very sorry for the long delay until reaching this state.

I think your package would benefit from having at least a somewhat realistic econometric example dataset built-in.

I agree the example is very far from the IV realm. It has one benefit however. By showing that the method gives results even for absurd data, it's a reminder that IVs are just a tool in the end, and causal statements can only be reached by other means than a simple regression. That said, 100% the examples should be improved.

Thanks for taking the time to write it.

lrberge commented 5 months ago

Sorry, on the IV I thought you made reference to: https://lrberge.github.io/fixest/articles/fixest_walkthrough.html#instrumental-variables

I agree with the suggestion. At some point I'll find the time to add a new data set and drop the AER suggest.