def __init__(self, df, y_name, x_name, z_name, w_name, **kwargs): super(IVReg, self).__init__(df, y_name, x_name, **kwargs) # Handle extra variable stuff for IV self.z_name = force_list(z_name) self.w_name = force_list(w_name) self.sample_cols_labels += ('z_name', 'w_name') self.sample_store_labels += ('z', 'w') self.vars_in_reg += ('z', 'w') self.add_constant_to = 'w'
def flag_sample(df, *args): varlist = [] for var in args: if var is not None: varlist += force_list(var) sample = df[varlist].notnull().all(axis=1) return sample
def __init__(self, df, y_name, x_name, **kwargs): self.df = df self.y_name = y_name self.__dict__.update(kwargs) self.sample_cols_labels = ( 'y_name', 'x_name', 'fe_name', 'cluster', 'shac_x', 'shac_y', 'awt_name' ) self.sample_store_labels = ( 'y', 'x', 'A', 'cluster_id', 'shac_x', 'shac_y', 'AWT' ) self.vars_in_reg = ('y', 'x') self.add_constant_to = 'x' # Set `vce_type` self.vce_type = _set_vce_type(self.vce_type, self.cluster, self.shac) # Unpack spatial HAC args sp_args = unpack_shac_args(self.shac) self.shac_x = sp_args[0] self.shac_y = sp_args[1] self.shac_band = sp_args[2] self.shac_kern = sp_args[3] # Force variable names to lists self.x_name = force_list(x_name)
def Ftest(self, col_names, equal=False): """F test using regression results. Args: col_names (str or list): Regressor name(s) to test. Keyword Args: equal (bool): Defaults to False. If True, test if all coefficients in ``col_names`` are equal. If False, test if ``col_names`` are jointly significant. Returns: tuple: A tuple containing: - **F** (float): F-stat. - **pF** (float): p-score for ``F``. """ cols = force_list(col_names) V = self.vce.loc[cols, cols] q = len(cols) beta = self.beta.loc[cols] if equal: q -= 1 R = np.zeros((q, q+1)) for i in range(q): R[i, i] = 1 R[i, i+1] = -1 else: R = np.eye(q) r = np.zeros(q) return f_test(V, R, beta, r, self.df_r)
def test_string(self): a_string = 'abcd' expected = [a_string] result = force_list(a_string) assert expected == result
def test_series(self): a_series = pd.Series(np.arange(3)) expected = a_series.tolist() result = force_list(a_series) assert expected == result
def test_array(self): an_array = np.arange(3) expected = an_array.tolist() result = force_list(an_array) assert expected == result
def test_tup(self): a_tuple = (1, 2, 3) expected = list(a_tuple) result = force_list(a_tuple) assert expected == result
def test_int(self): an_int = 10 expected = [an_int] result = force_list(an_int) assert expected == result
def test_list(self): expected = [1, 2, 3] result = force_list(expected) assert expected == result