Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Fixed Effects in a Regression

Hello,

Im developing a CustomFactor that uses a linear regression, I have been using the function regression from statsmodels

from statsmodels import regression  
results = regression.linear_model.OLS(y, X).fit()

I want to include firm fixed effects, my idea was to use

from linearmodels import PanelOLS  

But it seems like quantopian does not recognise that library. I also tried creating dummy variables for the assets in the CustomFactor but that is super inefficient and was taking a lot of time.

Has anyone used fixed effects in a regression in quantopian?

Thank you

2 responses

Hi,
I would recommend doing it using the statsmodel library, which has several options for robust standard errors - Statsmodel reference

Can also recommend these two papers on the topic for financial panel regressions:
Simple Formulas for Standard Errors that Cluster by Both Firm and Time

Estimating Standard Errors in Finance Panel Data Sets: Comparing Approaches

Hi,

You can model fixed effects by simply including dummy variables for the groups which you can get one hot encoded easily via pandas.get_dummies function