py-econometrics / pyfixest

Fast High-Dimensional Fixed Effects Regression in Python following fixest-syntax
https://py-econometrics.github.io/pyfixest/pyfixest.html
MIT License
118 stars 27 forks source link

Feols: Support for Gelbach's Regression Decomposition #429

Open s3alfisc opened 1 month ago

s3alfisc commented 1 month ago

Context:

Gelbach's decompositionis a useful tool in mediation analysis.

To do

apoorvalal commented 1 month ago

I have a self-contained implementation here fwiw; will need some refactoring but it is the same idea. np.linalg.lstsq(X, W, rcond=1)[0] will happily solve a multiple-outcome linear regression for you, which is the bulk of the work in Jonah's procedure.

s3alfisc commented 1 month ago

Oh that's just super cool! Would you mind to open a PR that adds your code in a standalone file? Then I could take over from there with refactoring & testing, but we wouldn't lose track of the fact that you are the initial author of the module?

Btw, looking at your nicely organized and object oriented implementation, two things come to my mind: in my first or second year of grad school, I tried myself at an R implementation of the decomposition and vaguely recall that my code was much, much more convoluted than your very concise implementation. I was truly terrible at coding back then ...

Second, I am feeling a little guilty about my non-OOP implementation of ritest. I might have to refactor it and introduce an Ritest class after all ... 😄

apoorvalal commented 1 month ago

Done

https://github.com/s3alfisc/pyfixest/pull/446

s3alfisc commented 1 month ago

Awesome, thank you!