I am currently using from pandas.stats.plm import PanelOLS
to run Panel regressions. I am needing to switch to statsmodel so that I can ouput heteroskedastic robust results. I have been unable to find notation on calling a panel regression for statsmodel. In general, I find the documentation for statsmodel not very user friendly. Is someone familiar with panel regression syntax in statsmodel?
statsmodel: panel regression
Asked Answered
The linearmodels
package is created to extend the statsmodels
package to panelOLS
(see https://github.com/bashtage/linearmodels). Here is the example from the package doc:
import numpy as np
from statsmodels.datasets import grunfeld
data = grunfeld.load_pandas().data
data.year = data.year.astype(np.int64)
# MultiIndex, entity - time
data = data.set_index(['firm','year'])
from linearmodels import PanelOLS
mod = PanelOLS(data.invest, data[['value','capital']], entity_effect=True)
res = mod.fit(cov_type='clustered', cluster_entity=True)
Best Daniel
© 2022 - 2024 — McMap. All rights reserved.
group_debias=True
to the last line if you want small-number of groups adjustment for clustered standard errors. – Compendious