Pandas: Key Error when implementing a Panel OLS

旧街凉风 提交于 2019-12-13 02:34:12

问题


I have the following dataframe:

url='https://raw.githubusercontent.com/108michael/ms_thesis/master/crsp.dime.mpl.df.1'

df=pd.read_csv(url, index_col=0)

df=df.pivot_table(index='date',columns='cid', fill_value=0,aggfunc=np.mean)

df=df.T.to_panel()

df=df.transpose(2,0,1)

df

<class 'pandas.core.panel.Panel'>
Dimensions: 505 (items) x 10 (major_axis) x 19 (minor_axis)
Items axis: N00000010 to N00035686
Major_axis axis: 2005 to 2014
Minor_axis axis: candcfscore.dyn_static to dir_ind_expendituresfor

I need to run a panel regression on it. To do that I am using the following code:

reg  = PanelOLS(y=df['billsum_support'],x=df[['years_exp', 'unemployment', 'dir_ind_expendituresfor']],time_effects=True)
reg

Which is giving me the following error: KeyError: 'billsum_support'

My understanding is that Items axisrepresents different data frames. Within each data frame I have different endogenousand exogenousvariables that I intend to implement for different regression outcomes.

I have looked and am continuing to look at some of the posts regarding Panel Fixed Effects in Pandas. It seems to be deprecated; does anyone has a clue on how to implement a simple Panel OLS in Pandas/Python?

来源:https://stackoverflow.com/questions/37100928/pandas-key-error-when-implementing-a-panel-ols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!