Beispiel #1
0
 def setup(self):
     res_ols = self.res1.model.fit(cov_type='cluster',
                                   cov_kwds=dict(groups=self.groups,
                                                 use_correction=True,
                                                 use_t=True))
     self.res3 = self.res1
     self.res1 = res_ols
     self.bse_robust = res_ols.bse
     self.cov_robust = res_ols.cov_params()
     cov1 = sw.cov_cluster(self.res1, self.groups, use_correction=True)
     se1 = sw.se_cov(cov1)
     self.bse_robust2 = se1
     self.cov_robust2 = cov1
Beispiel #2
0
 def setup(self):
     res_ols = self.res1.get_robustcov_results('cluster',
                                               groups=self.groups,
                                               use_correction=True,
                                               use_t=True)
     self.res3 = self.res1
     self.res1 = res_ols
     self.bse_robust = res_ols.bse
     self.cov_robust = res_ols.cov_params()
     cov1 = sw.cov_cluster(self.res1, self.groups, use_correction=True)
     se1 = sw.se_cov(cov1)
     self.bse_robust2 = se1
     self.cov_robust2 = cov1
Beispiel #3
0
    def setup(self):
        fat_array = self.groups.reshape(-1, 1)
        fat_groups = pd.DataFrame(fat_array)

        res_ols = self.res1.get_robustcov_results('cluster',
                                                  groups=fat_groups,
                                                  use_correction=True,
                                                  use_t=True)
        self.res3 = self.res1
        self.res1 = res_ols
        self.bse_robust = res_ols.bse
        self.cov_robust = res_ols.cov_params()
        cov1 = sw.cov_cluster(self.res1, self.groups, use_correction=True)
        se1 = sw.se_cov(cov1)
        self.bse_robust2 = se1
        self.cov_robust2 = cov1
Beispiel #4
0
def clustered_stderrs(self, res, kwds, cov_type, adjust_df):
    # cluster robust standard errors, one- or two-way
    n_groups = None

    groups = kwds['groups']
    if not hasattr(groups, 'shape'):
        groups = np.asarray(groups).T

    if groups.ndim >= 2:
        groups = groups.squeeze()

    res.cov_kwds['groups'] = groups
    use_correction = kwds.get('use_correction', True)
    res.cov_kwds['use_correction'] = use_correction
    if groups.ndim == 1:
        if adjust_df:
            # need to find number of groups
            # duplicate work
            self.n_groups = n_groups = len(np.unique(groups))
        cpd = sw.cov_cluster(self, groups, use_correction=use_correction)
        res.cov_params_default = cpd

    elif groups.ndim == 2:
        if hasattr(groups, 'values'):
            groups = groups.values

        if adjust_df:
            # need to find number of groups
            # duplicate work
            n_groups0 = len(np.unique(groups[:, 0]))
            n_groups1 = len(np.unique(groups[:, 1]))
            self.n_groups = (n_groups0, n_groups1)
            n_groups = min(n_groups0, n_groups1)  # use for adjust_df

        # Note: sw.cov_cluster_2groups has 3 returns
        cpd = sw.cov_cluster_2groups(self, groups,
                                     use_correction=use_correction)[0]
        res.cov_params_default = cpd
    else:  # pragma: no cover
        raise ValueError('only two groups are supported')

    res.cov_kwds['description'] = ('Standard Errors are robust to '
                                   'cluster correlation ({cov_type})'
                                   .format(cov_type=cov_type))
    return n_groups
Beispiel #5
0
 def get_robust_clu(cls):
     res1 = cls.res1
     cov_clu = sw.cov_cluster(res1, group)
     cls.bse_rob = sw.se_cov(cov_clu)
     cls.get_corr_fact()