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 = 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 output = '\n' output += 'Stratification Summary\n\n' entries1 = [ '', 'Propensity Score', 'Sample Size', 'Ave. Propensity', 'Outcome' ] entry_types1 = ['string'] * 5 col_spans1 = [1, 2, 2, 2, 1] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) entries2 = [ 'Stratum', 'Min.', 'Max.', 'Controls', 'Treated', 'Controls', 'Treated', ] entry_types3 = [ 'integer', 'float', 'float', 'integer', 'integer', 'float', 'float', ] strata = self._strata for i, rdiff in enumerate(strata[0].summary_stats['rdiff']): entries2.append('Y{} raw-diff'.format(i)) entry_types3.append('float') entry_types2 = ['string'] * len(entries2) col_spans2 = [1] * len(entries2) output += tools.add_row(entries2, entry_types2, col_spans2, table_width) output += tools.add_line(table_width) for i in range(len(strata)): summary = strata[i].summary_stats N_c, N_t = summary['N_c'], summary['N_t'] p_min, p_max = summary['p_min'], summary['p_max'] p_c_mean = summary['p_c_mean'] p_t_mean = summary['p_t_mean'] entries3 = [i + 1, p_min, p_max, N_c, N_t, p_c_mean, p_t_mean] for rdiff in summary['rdiff']: entries3.append(rdiff) output += tools.add_row(entries3, entry_types3, col_spans2, table_width) return output
def test_add_row(): entries1 = ('Variable', 'Mean', 'S.d.', 'Mean', 'S.d.', 'Raw diff') entry_types1 = ['string']*6 col_spans1 = [1]*6 width1 = 80 ans1 = ' Variable Mean S.d. Mean S.d. Raw diff\n' assert_equal(t.add_row(entries1, entry_types1, col_spans1, width1), ans1) entries2 = [12, 13.2, -3.14, 9.8765] entry_types2 = ['integer', 'integer', 'float', 'float'] col_spans2 = [1, 2, 2, 1] width2 = 80 ans2 = ' 12 13 -3.140 9.877\n' assert_equal(t.add_row(entries2, entry_types2, col_spans2, width2), ans2)
def __str__(self): table_width = 80 output = '\n' output += 'Stratification Summary\n\n' entries1 = [ '', 'Propensity Score', 'Sample Size', 'Ave. Propensity', 'Outcome' ] entry_types1 = ['string'] * 5 col_spans1 = [1, 2, 2, 2, 1] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) entries2 = [ 'Stratum', 'Min.', 'Max.', 'Controls', 'Treated', 'Controls', 'Treated', 'Raw-diff' ] entry_types2 = ['string'] * 8 col_spans2 = [1] * 8 output += tools.add_row(entries2, entry_types2, col_spans2, table_width) output += tools.add_line(table_width) strata = self._strata entry_types3 = [ 'integer', 'float', 'float', 'integer', 'integer', 'float', 'float', 'float' ] for i in range(len(strata)): summary = strata[i].summary_stats N_c, N_t = summary['N_c'], summary['N_t'] p_min, p_max = summary['p_min'], summary['p_max'] p_c_mean = summary['p_c_mean'] p_t_mean = summary['p_t_mean'] within = summary['rdiff'] entries3 = [ i + 1, p_min, p_max, N_c, N_t, p_c_mean, p_t_mean, within ] output += tools.add_row(entries3, entry_types3, 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 __str__(self): table_width = 80 output = '\n' output += 'Stratification Summary\n\n' entries1 = ['', 'Propensity Score', 'Sample Size', 'Ave. Propensity', 'Outcome'] entry_types1 = ['string']*5 col_spans1 = [1, 2, 2, 2, 1] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) entries2 = ['Stratum', 'Min.', 'Max.', 'Controls', 'Treated', 'Controls', 'Treated', 'Raw-diff'] entry_types2 = ['string']*8 col_spans2 = [1]*8 output += tools.add_row(entries2, entry_types2, col_spans2, table_width) output += tools.add_line(table_width) strata = self._strata entry_types3 = ['integer', 'float', 'float', 'integer', 'integer', 'float', 'float', 'float'] for i in range(len(strata)): summary = strata[i].summary_stats N_c, N_t = summary['N_c'], summary['N_t'] p_min, p_max = summary['p_min'], summary['p_max'] p_c_mean = summary['p_c_mean'] p_t_mean = summary['p_t_mean'] within = summary['rdiff'] entries3 = [i+1, p_min, p_max, N_c, N_t, p_c_mean, p_t_mean, within] output += tools.add_row(entries3, entry_types3, col_spans2, table_width) return output
def __str__(self): table_width = 80 N_c, N_t, K = self['N_c'], self['N_t'], self['K'] Y_c_mean, Y_t_mean = self['Y_c_mean'], self['Y_t_mean'] Y_c_sd, Y_t_sd = self['Y_c_sd'], self['Y_t_sd'] X_c_mean, X_t_mean = self['X_c_mean'], self['X_t_mean'] X_c_sd, X_t_sd = self['X_c_sd'], self['X_t_sd'] rdiff, ndiff = self['rdiff'], self['ndiff'] varnames = ['X'+str(i) for i in range(K)] outputnames = ['Y'+str(i) for i in range(self['num_outputs'])] output = '\n' output += 'Summary Statistics\n\n' entries1 = ['', 'C (N_c='+str(N_c)+')', 'T (N_t='+str(N_t)+')', ''] entry_types1 = ['string']*4 col_spans1 = [1, 2, 2, 1] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) entries2 = ['Variable', 'Mean', 'S.d.', 'Mean', 'S.d.', 'rdif'] entry_types2 = ['string']*6 col_spans2 = [1]*6 output += tools.add_row(entries2, entry_types2, col_spans2, table_width) output += tools.add_line(table_width) entries3 = ['Y', Y_c_mean, Y_c_sd, Y_t_mean, Y_t_sd, rdiff] entry_types3 = ['string'] + ['float']*5 col_spans3 = [1]*6 for entries3 in zip(outputnames, Y_c_mean, Y_c_sd, Y_t_mean, Y_t_sd, rdiff): output += tools.add_row(entries3, entry_types3, col_spans3, table_width) output += '\n' output += tools.add_row(entries1, entry_types1, col_spans1, table_width) entries4 = ['Variable', 'Mean', 'S.d.', 'Mean', 'S.d.', 'Ndif'] output += tools.add_row(entries4, entry_types2, col_spans2, table_width) output += tools.add_line(table_width) entry_types5 = ['string'] + ['float']*5 col_spans5 = [1]*6 for entries5 in zip(varnames, X_c_mean, X_c_sd, X_t_mean, X_t_sd, ndiff): output += tools.add_row(entries5, entry_types5, col_spans5, table_width) return output
def __str__(self): table_width = 80 N_c, N_t, K = self["N_c"], self["N_t"], self["K"] Y_c_mean, Y_t_mean = self["Y_c_mean"], self["Y_t_mean"] Y_c_sd, Y_t_sd = self["Y_c_sd"], self["Y_t_sd"] X_c_mean, X_t_mean = self["X_c_mean"], self["X_t_mean"] X_c_sd, X_t_sd = self["X_c_sd"], self["X_t_sd"] rdiff, ndiff = self["rdiff"], self["ndiff"] varnames = ["X" + str(i) for i in range(K)] output = "\n" output += "Summary Statistics\n\n" entries1 = ["", "Controls (N_c=" + str(N_c) + ")", "Treated (N_t=" + str(N_t) + ")", ""] entry_types1 = ["string"] * 4 col_spans1 = [1, 2, 2, 1] output += tools.add_row(entries1, entry_types1, col_spans1, table_width) entries2 = ["Variable", "Mean", "S.d.", "Mean", "S.d.", "Raw-diff"] entry_types2 = ["string"] * 6 col_spans2 = [1] * 6 output += tools.add_row(entries2, entry_types2, col_spans2, table_width) output += tools.add_line(table_width) entries3 = ["Y", Y_c_mean, Y_c_sd, Y_t_mean, Y_t_sd, rdiff] entry_types3 = ["string"] + ["float"] * 5 col_spans3 = [1] * 6 output += tools.add_row(entries3, entry_types3, col_spans3, table_width) output += "\n" output += tools.add_row(entries1, entry_types1, col_spans1, table_width) entries4 = ["Variable", "Mean", "S.d.", "Mean", "S.d.", "Nor-diff"] output += tools.add_row(entries4, entry_types2, col_spans2, table_width) output += tools.add_line(table_width) entry_types5 = ["string"] + ["float"] * 5 col_spans5 = [1] * 6 for entries5 in zip(varnames, X_c_mean, X_c_sd, X_t_mean, X_t_sd, ndiff): output += tools.add_row(entries5, entry_types5, col_spans5, table_width) return output