首页 > 解决方案 > 如何在python中运行固定效应回归

问题描述

我想用大学的固定效应和年份的固定效应进行回归。

# Import the packages
import pandas as pd
from linearmodels import PanelOLS
import statsmodels.api as sm


# Load the data
data = pd.read_csv(r"https://raw.githubusercontent.com/LOST-STATS/LOST-STATS.github.io/master/Model_Estimation/Data/Fixed_Effects_in_Linear_Regression/Scorecard.csv")

# Set the index for fixed effects
data = data.set_index(['inst_name', 'year'])

# Calculate and drop the NA Values
data['prop_working'] = data['count_working']/(data['count_working'] + data['count_not_working'])
data = data.dropna(subset=['earnings_med', 'prop_working'])


# Regression
FE = PanelOLS(data.earnings_med, data['prop_working'], entity_effects = True, time_effects=True)
print(FE.fit(cov_type = 'clustered',  entity_effects = True, time_effects=True))

但是,估计值与在 R 中使用的相同,felm但标准差远小于 R 中的值。估计值应在 21876 左右,标准差应在 1669 左右

我想知道如何编辑它,以便它们至少可以得到相似的结果......

标签: pythonrstatistics

解决方案


推荐阅读