固定效果 pandas [英] Pandas with Fixed Effects

查看:120
本文介绍了固定效果 pandas 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python 2.7上使用Pandas.我有以下各列的数据: 状态,年份,失业率,工资

我正在教授一门有关如何使用Python进行研究的课程.作为我们项目的高潮,我想对用于州和年份固定效应的工资控制进行UnempRate回归分析.

我可以通过为州和年份创建虚拟变量来实现,然后:

ols(y=df['UnempRate'],x=df[FullDummyList])

有没有更简单的方法可以做到这一点?我正在尝试使用此处提到的PanelOLS方法: 在Pandas或Statsmodels中的固定效果

但是我似乎无法正确理解语法,也找不到更多文档.

谢谢!

解决方案

为固定效果创建虚拟变量的最简单方法是使用patsy,或通过公式接口将其用于statsmodels中的模型.

Statsmodels.OLS以及GLM和离散模型也可以选择为参数估计计算聚类或面板鲁棒(三明治)协方差矩阵.从0.6版开始,可以通过fit方法中的cov_type选项指定.

statsmodels当前没有面板模型可以考虑跨观察的相关性,但是GEE允许在静态面板或纵向模型中进行单向群集相关.

我不知道有关熊猫的面板估计的详细信息,但是它没有得到维护,最终将被移至statsmodels或由statsmodels代替.

I'm using Pandas on Python 2.7. I have data with the following columns: State, Year, UnempRate, Wage

I'm teaching a course on how to use Python for research. As the culmination of our project, I want to run a regression of UnempRate on Wage controlling for State and Year fixed effects.

I can do this with creation of dummies for states and year and then:

ols(y=df['UnempRate'],x=df[FullDummyList])

Is there an easier way to do this? I was trying to use the PanelOLS method mentioned here: Fixed effect in Pandas or Statsmodels

But I can't seem to get the syntax right, or find more documentation on it.

Thanks!

解决方案

The simplest way to create the dummy variables for the fixed effects is using patsy, or using it via the formula interface to the models in statsmodels.

Statsmodels.OLS, as well as GLM and the discrete models, also have an option to calculate cluster or panel robust (sandwich) covariance matrices for the parameter estimates. Since release 0.6 this can be specified by a cov_type option in the fit method.

statsmodels has currently no panel models that could take correlation across observations into account, however GEE allows one-way cluster correlation in static panel or longitudinal models.

I don't know the details about the panel estimation in pandas, but it's not maintained and will eventually be moved to or replaced by statsmodels.

这篇关于固定效果 pandas 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆