首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用鲁棒标准错误时,Python和Stata的linearmodels.PanelOLS之间标准错误的差异

在使用鲁棒标准错误时,Python和Stata的linearmodels.PanelOLS之间标准错误的差异
EN

Stack Overflow用户
提问于 2020-05-05 19:06:27
回答 1查看 461关注 0票数 1

我从线性模型PanelOLS介绍中复制了一个example,并包含了健壮的标准错误,以了解如何使用该模块。下面是我使用的代码

代码语言:javascript
复制
from linearmodels.datasets import jobtraining
import statsmodels.api as sm2
data = jobtraining.load()
mi_data = data.set_index(['fcode', 'year'])
mi_data.head()
from linearmodels import PanelOLS
mod = PanelOLS(mi_data.lscrap, sm2.add_constant(mi_data.hrsemp), entity_effects=True)
print(mod.fit(cov_type='robust'))

                          PanelOLS Estimation Summary                           
================================================================================
Dep. Variable:                 lscrap   R-squared:                        0.0528
Estimator:                   PanelOLS   R-squared (Between):             -0.0029
No. Observations:                 140   R-squared (Within):               0.0528
Date:                Tue, May 05 2020   R-squared (Overall):              0.0048
Time:                        10:49:58   Log-likelihood                   -90.459
Cov. Estimator:                Robust                                           
                                        F-statistic:                      5.0751
Entities:                          48   P-value                           0.0267
Avg Obs:                       2.9167   Distribution:                    F(1,91)
Min Obs:                       1.0000                                           
Max Obs:                       3.0000   F-statistic (robust):             8.2299
                                        P-value                           0.0051
Time periods:                       3   Distribution:                    F(1,91)
Avg Obs:                       46.667                                           
Min Obs:                       46.000                                           
Max Obs:                       48.000                                           

                             Parameter Estimates                              
==============================================================================
            Parameter  Std. Err.     T-stat    P-value    Lower CI    Upper CI
------------------------------------------------------------------------------
const          0.4982     0.0555     8.9714     0.0000      0.3879      0.6085
hrsemp        -0.0054     0.0019    -2.8688     0.0051     -0.0092     -0.0017
==============================================================================

F-test for Poolability: 17.094
P-value: 0.0000
Distribution: F(47,91)

Included effects: Entity

当我将结果与我如何使用健壮的标准误差执行固定效果回归进行比较时,我发现标准误差非常不同。

代码语言:javascript
复制
xtset fcode year
xtreg lscrap hrsemp  , fe vce(robust)
Fixed-effects (within) regression               Number of obs      =       140
Group variable: fcode                           Number of groups   =        48

R-sq:  within  = 0.0528                         Obs per group: min =         1
       between = 0.0002                                        avg =       2.9
       overall = 0.0055                                        max =         3

                                                F(1,47)            =      7.93
corr(u_i, Xb)  = -0.0266                        Prob > F           =    0.0071

                                 (Std. Err. adjusted for 48 clusters in fcode)
------------------------------------------------------------------------------
             |               Robust
      lscrap |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      hrsemp |  -.0054186   .0019243    -2.82   0.007    -.0092897   -.0015474
       _cons |   .4981764   .0295415    16.86   0.000     .4387464    .5576063
-------------+----------------------------------------------------------------
     sigma_u |  1.4004191
     sigma_e |  .57268937
         rho |  .85672692   (fraction of variance due to u_i)
------------------------------------------------------------------------------

我不明白差异来自哪里,因为如果没有强大的SE,结果(几乎)是相同的。如何使用Pythons linearmodels.PanelOLS在Stata中使用相同的健壮SE?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-06 00:54:19

怀特的稳健协方差,在Python中与cov_type='robust'选项一起使用,对于固定效果模型是不稳健的。您应该改用cov_type='robust',cluster_entity=True。以下是来自线性模型的相应manual entry

完整代码:

代码语言:javascript
复制
from linearmodels.datasets import jobtraining
import statsmodels.api as sm2
data = jobtraining.load()
mi_data = data.set_index(['fcode', 'year'])
mi_data.head()
from linearmodels import PanelOLS
mod = PanelOLS(mi_data.lscrap, sm2.add_constant(mi_data.hrsemp), entity_effects=True)
print(mod.fit(cov_type='robust',cluster_entity=True)) 

相应的输出几乎与Stata的输出相似:

代码语言:javascript
复制
                          PanelOLS Estimation Summary                           
================================================================================
Dep. Variable:                 lscrap   R-squared:                        0.0528
Estimator:                   PanelOLS   R-squared (Between):             -0.0029
No. Observations:                 140   R-squared (Within):               0.0528
Date:                Tue, May 05 2020   R-squared (Overall):              0.0048
Time:                        18:53:06   Log-likelihood                   -90.459
Cov. Estimator:                Robust                                           
                                        F-statistic:                      5.0751
Entities:                          48   P-value                           0.0267
Avg Obs:                       2.9167   Distribution:                    F(1,91)
Min Obs:                       1.0000                                           
Max Obs:                       3.0000   F-statistic (robust):             8.2299
                                        P-value                           0.0051
Time periods:                       3   Distribution:                    F(1,91)
Avg Obs:                       46.667                                           
Min Obs:                       46.000                                           
Max Obs:                       48.000                                           

                             Parameter Estimates                              
==============================================================================
            Parameter  Std. Err.     T-stat    P-value    Lower CI    Upper CI
------------------------------------------------------------------------------
const          0.4982     0.0555     8.9714     0.0000      0.3879      0.6085
hrsemp        -0.0054     0.0019    -2.8688     0.0051     -0.0092     -0.0017
==============================================================================

F-test for Poolability: 17.094
P-value: 0.0000
Distribution: F(47,91)

Included effects: Entity
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61611668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档