I'm working with water and sewage provision data from Brazil, 5500 obs, unbalanced panel.
I want to estimate a correlated random effects (CRE) model, and since Wooldridge tells that estimates are the same under CRE and fixed effects I estimated the two models to see if I got it right, but they are quite different. Can anyone tell me if is it a code flaw?
The code I wrote (also, code suggestions are welcome):
import pandas as pd
import linearmodels
data = pd.read_csv(path + 'final_base4.csv')
data = data.set_index(['level_0', 'level_1'])
cre_estimates = {}
fe_estimates = {}
xit = ['lnPIBpc_m', 'in004_', 'const']
di = ['PIBpc_m_bar', 'in004_bar',
'2011', '2012', '2013', '2014',
'2015', '2016', '2017', '2018']
y = ['lnfn033__m', 'lntotinv_m',
'lnfn033_pop', 'lntotinv_pop',
'lnfn033_eh2o', 'lntotinv_eh2o',
'lnfn033_toteh2o', 'lntotinv_toteh2o']
for i in range(len(y)):
# Correlated Random Effects
cre_estimates[f'{y[i]}'] = linearmodels.RandomEffects(data[y[i]],
data[xit + di])
cre_estimates[f'{y[i]}_robs'] = cre_estimates[f'{y[i]}'].fit(cov_type='clustered',
entity_cluster=True)
cre_estimates[f'{y[i]}_hac'] = cre_estimates[f'{y[i]}'].fit(cov_type='kernel')
cre_estimates[f'{y[i]}'] = cre_estimates[f'{y[i]}'].fit()
# Fixed Effects
fe_estimates[f'{y[i]}'] = linearmodels.PanelOLS(data[y[i]], data[xit + di],
entity_effects=True,
drop_absorbed=True)
fe_estimates[f'{y[i]}_hac'] = fe_estimates[f'{y[i]}'].fit(cov_type='kernel')
fe_estimates[f'{y[i]}_robs'] = fe_estimates[f'{y[i]}'].fit(cov_type='clustered',
entity_cluster=True)
fe_estimates[f'{y[i]}'] = fe_estimates[f'{y[i]}'].fit()
print(linearmodels.panel.compare({'Correlated Random Effects': cre_estimates['lnfn033__m'],
'Fixed Effects': fe_estimates['lnfn033__m']}))
Print of the estimates