def __str__(self): table_width = 100 names = estimation_names() coefs = [self[name] for name in names if name in self.keys()] ses = [self[name] for name in standard_err_names() if name in self.keys()] output = '\n' output += 'Treatment Effect Estimates: ' + self._method + '\n\n' entries1 = ['', 'Est.', 'S.e.', 'z', 'P>|z|', '[95% Conf. int.]'] entry_types1 = ['string']*6 col_spans1 = [1]*5 + [2] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) output += tools.add_line(table_width) entry_types2 = ['string'] + ['float']*6 col_spans2 = [1]*7 for (name, coef, se) in zip(names, coefs, ses): for i, (coef_val, se_val) in enumerate(zip(coef, se)): entries2 = tools.gen_reg_entries( 'Y{}: {}'.format(i, name.upper()), coef_val, se_val) output += tools.add_row(entries2, entry_types2, col_spans2, table_width) return output
def __str__(self): table_width = 80 names = ['ate', 'atc', 'att'] coefs = [self[name] for name in names if name in self.keys()] ses = [self[name+'_se'] for name in names if name+'_se' in self.keys()] output = '\n' output += 'Treatment Effect Estimates: ' + self._method + '\n\n' entries1 = ['', 'Est.', 'S.e.', 'z', 'P>|z|', '[95% Conf. int.]'] entry_types1 = ['string']*6 col_spans1 = [1]*5 + [2] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) output += tools.add_line(table_width) entry_types2 = ['string'] + ['float']*6 col_spans2 = [1]*7 for (name, coef, se) in zip(names, coefs, ses): entries2 = tools.gen_reg_entries(name.upper(), coef, se) output += tools.add_row(entries2, entry_types2, col_spans2, table_width) return output
def __str__(self): table_width = 80 names = ['ate', 'atc', 'att'] coefs = [self[name] for name in names if name in self.keys()] ses = [ self[name + '_se'] for name in names if name + '_se' in self.keys() ] output = '\n' output += 'Treatment Effect Estimates: ' + self._method + '\n\n' entries1 = ['', 'Est.', 'S.e.', 'z', 'P>|z|', '[95% Conf. int.]'] entry_types1 = ['string'] * 6 col_spans1 = [1] * 5 + [2] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) output += tools.add_line(table_width) entry_types2 = ['string'] + ['float'] * 6 col_spans2 = [1] * 7 for (name, coef, se) in zip(names, coefs, ses): entries2 = tools.gen_reg_entries(name.upper(), coef, se) output += tools.add_row(entries2, entry_types2, col_spans2, table_width) return output
def __str__(self): table_width = 80 coefs = self._dict['coef'] ses = self._dict['se'] output = '\n' output += 'Estimated Parameters of Propensity Score\n\n' entries1 = ['', 'Coef.', 'S.e.', 'z', 'P>|z|', '[95% Conf. int.]'] entry_types1 = ['string']*6 col_spans1 = [1]*5 + [2] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) output += tools.add_line(table_width) entries2 = tools.gen_reg_entries('Intercept', coefs[0], ses[0]) entry_types2 = ['string'] + ['float']*6 col_spans2 = [1]*7 output += tools.add_row(entries2, entry_types2, col_spans2, table_width) lin = self._dict['lin'] for (lin_term, coef, se) in zip(lin, coefs[1:], ses[1:]): entries3 = tools.gen_reg_entries('X'+str(lin_term), coef, se) output += tools.add_row(entries3, entry_types2, col_spans2, table_width) qua = self._dict['qua'] lin_num = len(lin)+1 # including intercept for (qua_term, coef, se) in zip(qua, coefs[lin_num:], ses[lin_num:]): name = 'X'+str(qua_term[0])+'*X'+str(qua_term[1]) entries4 = tools.gen_reg_entries(name, coef, se) output += tools.add_row(entries4, entry_types2, col_spans2, table_width) return output
def as_rows(self): names = estimation_names() coefs = [self[name] for name in names if name in self.keys()] ses = [self[name] for name in standard_err_names() if name in self.keys()] r2s = self['r2'] rows = [('Est.', 'S.e.', 'z', 'P>|z|', '[95% Conf. int.]')] for (name, coef, se) in zip(names, coefs, ses): for i, (coef_val, se_val) in enumerate(zip(coef, se)): row = list(tools.gen_reg_entries( 'Y{}: {}'.format(i, name.upper()), coef_val, se_val))[1:] rows.append(row) return rows
def test_gen_reg_entries(): varname = 'Income' coef = 0.5 se = 0.25 ans1 = 'Income' ans2 = 0.5 ans3 = 0.25 ans4 = 2 ans5 = 0.045500 ans6 = 0.01 ans7 = 0.99 v, c, s, z, p, lw, up = t.gen_reg_entries(varname, coef, se) assert_equal(v, ans1) assert_equal(c, ans2) assert_equal(s, ans3) assert_equal(z, ans4) assert np.allclose(p, ans5) assert np.allclose(lw, ans6) assert np.allclose(up, ans7)