def test_original_unmodified(data): pre_y = data.y.copy() pre_x = data.x.copy() pre_w = data.w.copy() mod = PanelOLS(data.y, data.x, weights=data.w) mod.fit(debiased=True) if isinstance(data.y, (DataFrame)): for after, before in ((data.y, pre_y), (data.x, pre_x), (data.w, pre_w)): assert_frame_equal(before, after) mi_df_y = PanelData(data.y).dataframe mi_df_x = PanelData(data.x).dataframe mi_df_y.index.names = ["firm", "period"] mi_df_x.index.names = ["firm", "period"] mi_df_w = PanelData(data.w).dataframe pre_y = mi_df_y.copy() pre_x = mi_df_x.copy() pre_w = mi_df_w.copy() mod = PanelOLS(mi_df_y, mi_df_x, weights=mi_df_w) mod.fit(debiased=True) assert_frame_equal(mi_df_w, pre_w) assert_frame_equal(mi_df_y, pre_y) assert_frame_equal(mi_df_x, pre_x) elif isinstance(data.y, np.ndarray): assert_allclose(data.y, pre_y) assert_allclose(data.x, pre_x) assert_allclose(data.w, pre_w) else: xr.testing.assert_identical(data.y, pre_y) xr.testing.assert_identical(data.w, pre_w) xr.testing.assert_identical(data.x, pre_x)
def const_data(request): missing, datatype = request.param data = generate_data(missing, datatype, ntk=(91, 7, 1)) y = PanelData(data.y).dataframe x = y.copy() x.iloc[:, :] = 1 x.columns = ['Const'] return AttrDict(y=y, x=x, w=PanelData(data.w).dataframe)
def test_two_way_clustering(data): mod = PooledOLS(data.y, data.x) y = PanelData(data.y) entity_clusters = pd.DataFrame(y.entity_ids, index=y.index) vc1 = PanelData(data.vc1) clusters = vc1.copy() clusters.dataframe['var.cluster.entity'] = entity_clusters clusters._frame = clusters._frame.astype(np.int64) res = mod.fit(cov_type='clustered', clusters=clusters, debiased=False) y = mod.dependent.dataframe.copy() x = mod.exog.dataframe.copy() y.index = np.arange(len(y)) x.index = y.index clusters = mod.reformat_clusters(clusters) ols_mod = IV2SLS(y, x, None, None) ols_res = ols_mod.fit(cov_type='clustered', clusters=clusters.dataframe) assert_results_equal(res, ols_res)
ntk=(n, 3, 5), other_effects=1, const=False, rng=rs) mo, fo = options[key] mod_type, cluster_type = key.split(':') y = PanelData(data.y) random_effects = np.random.randint(0, n // 3, size=y.dataframe.shape) other_random = np.random.randint(0, n // 5, size=y.dataframe.shape) if mod_type == 'random': effects = y.copy() effects.dataframe.iloc[:, :] = random_effects mo['other_effects'] = effects if cluster_type in ('random', 'other-random', 'entity-nested', 'random-nested'): clusters = y.copy() if cluster_type == 'random': clusters.dataframe.iloc[:, :] = random_effects elif cluster_type == 'other-random': clusters.dataframe.iloc[:, :] = other_random elif cluster_type == 'entity_nested': eid = y.entity_ids clusters.dataframe.iloc[:, :] = eid // 3 elif cluster_type == 'random-nested': clusters.dataframe.iloc[:, :] = random_effects // 2