bashtage/linearmodels

ValueError: Series can only be used with a 2-level MultiIndex

jonnatakusuma opened this issue · 2 comments

Hi,

I tried implementing the following codes but came up with a 2-level multiindex error. Can you please help:

data = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)],
                dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")])
df3 = pd.DataFrame(data, columns=['c', 'a'])
exog = sm.tools.tools.add_constant(df3['a'])
endog = df3['c']
# random effects model
model_re = RandomEffects(endog, exog) 
re_res = model_re.fit() 
# fixed effects model
model_fe = PanelOLS(endog, exog, entity_effects = True) 
fe_res = model_fe.fit() 
#print results
print(re_res)
print(fe_res)

You need to have a 2-level index with level[0] being entity and level[1] being time.

Going to close as answered, but feel free to continue to post if not clear.