0

我正在尝试使用线性模型(版本 4.8)中的 FamaMacBeth 功能运行一些 Fama MacBeth 回归,但遇到以下错误:

ValueError                                Traceback (most recent call last)
 <ipython-input-7-f393d4c071f0> in do_panel(list_dfs, y_var, control_vars, 
method)
      37         print(fmb_df[y_var].head())
      38         print(fmb_df[new_x_vars].head())
 ---> 39         model = FamaMacBeth(fmb_df[y_var], sm.add_constant(fmb_df[new_x_vars])).fit()
      40     return model
      41 

~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\linearmodels\panel\model.py in fit(self, cov_type, debiased, **cov_config)
     1940         cov = cov_est(wy, wx, params, all_params, debiased=debiased, **cov_config)
     1941         df_resid = wy.shape[0] - params.shape[0]
  -> 1942         res = self._postestimation(params, cov, debiased, df_resid, weps, wy, wx, root_w)
     1943         index = self.dependent.index
     1944         res.update(dict(df_resid=df_resid, df_model=x.shape[1], nobs=y.shape[0],

 ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\linearmodels\panel\model.py in _postestimation(self, params, cov, debiased, df_resid, weps, y, x, root_w)
     441         f_pooled = InapplicableTestStatistic(reason='Model has no effects',
     442                                              name='Pooled F-stat')
 --> 443         entity_info, time_info, other_info = self._info()
     444         nobs = weps.shape[0]
     445         sigma2 = float(weps.T @ weps / nobs)

 ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\linearmodels\panel\model.py in _info(self)
     223 
     224         entity_info = stats(self.dependent.entity_ids.squeeze(),
 --> 225                             'Observations per entity')
     226         time_info = stats(self.dependent.time_ids.squeeze(),
     227                           'Observations per time period')

 ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\linearmodels\panel\model.py in stats(ids, name)
     217 
     218         def stats(ids, name):
 --> 219             bc = np.bincount(ids)
     220             index = ['mean', 'median', 'max', 'min', 'total']
     221             out = [bc.mean(), np.median(bc), bc.max(), bc.min(), bc.shape[0]]

ValueError: 'list' argument must have no negative elements

我尝试谷歌搜索,我得到的唯一其他命中来自 numpy 源: https ://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/compiled_base.c

我终其一生都无法弄清楚出了什么问题。当然,我的 pandas DataFrame 中的值允许为负数,对吗?非常感谢您的帮助,非常感谢您!

编辑:更新了详细的错误回溯。

4

0 回答 0