简体   繁体   English

Python:PanelOLS-双向群集?

[英]Python: PanelOLS - two-way clustering?

In Python/Pandas I use the PanelOLS function. 在Python / Pandas中,我使用PanelOLS函数。 This function gives you the ability to cluster your standard errors. 此功能使您能够聚类标准错误。 For instance: 例如:

PanelOLS(y=panel.Y, x=panel[['X1', 'X2'], nw_lags=10, time_effects=True,
         cluster='time')

But I would like to also cluster by standard errors by entity as well as in time . 但我也想按entity以及按time按标准错误进行聚类。

Is there a way to do so? 有办法吗? If not, what about the panel function in statsmodel ? 如果不是,那statsmodel的面板功能呢? I have a hard time to find the documentation on Panel regression using statsmodel. 我很难使用statsmodel查找有关Panel回归的文档。

UPDATE If I control using the newey-west lags ( nw_lags ) , isn't this like cluster='entity' ? 更新如果我使用newey-west lags( nw_lags )进行控制,这是否不像cluster='entity' So, if I use both nw_lags and cluster=time , it is like doing a 2-way clustering? 所以,如果我同时使用nw_lagscluster=time ,那就像做2向集群一样?

In Thompson (2011) "Simple Formulas for standard errors that cluster by both frim and time" he describes how you can achieve double-clustering with commands that allow only one way clustering. 在汤普森(Thompson,2011)中,“标准误差的简单公式同时按照时间和时间进行聚类”,他描述了如何使用仅允许单向聚类的命令实现双聚类。

Denote your variance estimator clustered by entity by V_ent and your variance estimator clustered by time by V_time and the heteroskedasticity-robust estimator by V_white . 记由实体聚集你的方差估计V_ent并通过时间聚集你的方差估计V_time并通过异方差稳健估计V_white Then the double clustering standard error is given by V = V_ent + V_time - V_white . 然后,通过V = V_ent + V_time - V_white给出双聚类标准误差。 So you can use your PanelOLS regression to give you each of these variance estimators and then compute the double-clustering standard errors by yourself. 因此,您可以使用PanelOLS回归为您提供这些方差估计量中的每一个,然后自己计算出双聚类标准误差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM