首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >statsmodels.api.ols中的固定效应

statsmodels.api.ols中的固定效应
EN

Stack Overflow用户
提问于 2022-02-16 10:52:43
回答 1查看 625关注 0票数 0

是否有一种方法可以在statsmodels.api.olsstatsmodels.formula.api.ols中添加固定效果而无需手动创建虚拟变量?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-16 12:50:59

statsmodels不支持固定效应回归。但是,包linearmodels是这样做的。

代码语言:javascript
复制
from linearmodels.panel import PanelOLS
import pandas as pd
from linearmodels.datasets import wage_panel
import statsmodels.api as sm

data = wage_panel.load()
year = pd.Categorical(data.year)
data = data.set_index(["nr", "year"])
data["year"] = year

exog_vars = ["expersq", "union", "married", "year"]
exog = sm.add_constant(data[exog_vars])
mod = PanelOLS(data.lwage, exog, entity_effects=True)
fe_res = mod.fit()
print(fe_res)

这个指纹

代码语言:javascript
复制
                          PanelOLS Estimation Summary
================================================================================
Dep. Variable:                  lwage   R-squared:                        0.1806
Estimator:                   PanelOLS   R-squared (Between):             -0.0052
No. Observations:                4360   R-squared (Within):               0.1806
Date:                Wed, Feb 16 2022   R-squared (Overall):              0.0807
Time:                        12:49:00   Log-likelihood                   -1324.8
Cov. Estimator:            Unadjusted
                                        F-statistic:                      83.851
Entities:                         545   P-value                           0.0000
Avg Obs:                       8.0000   Distribution:                 F(10,3805)
Min Obs:                       8.0000
Max Obs:                       8.0000   F-statistic (robust):             83.851
                                        P-value                           0.0000
Time periods:                       8   Distribution:                 F(10,3805)
Avg Obs:                       545.00
Min Obs:                       545.00
Max Obs:                       545.00

                             Parameter Estimates
==============================================================================
            Parameter  Std. Err.     T-stat    P-value    Lower CI    Upper CI
------------------------------------------------------------------------------
const          1.4260     0.0183     77.748     0.0000      1.3901      1.4620
expersq       -0.0052     0.0007    -7.3612     0.0000     -0.0066     -0.0038
union          0.0800     0.0193     4.1430     0.0000      0.0421      0.1179
married        0.0467     0.0183     2.5494     0.0108      0.0108      0.0826
year.1981      0.1512     0.0219     6.8883     0.0000      0.1082      0.1942
year.1982      0.2530     0.0244     10.360     0.0000      0.2051      0.3008
year.1983      0.3544     0.0292     12.121     0.0000      0.2971      0.4118
year.1984      0.4901     0.0362     13.529     0.0000      0.4191      0.5611
year.1985      0.6175     0.0452     13.648     0.0000      0.5288      0.7062
year.1986      0.7655     0.0561     13.638     0.0000      0.6555      0.8755
year.1987      0.9250     0.0688     13.450     0.0000      0.7902      1.0599
==============================================================================

F-test for Poolability: 9.1568
P-value: 0.0000
Distribution: F(544,3805)

Included effects: Entity

Included effects: Entity表示已经包含了实体(也称为固定的)效果。

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

https://stackoverflow.com/questions/71140464

复制
相关文章

相似问题

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