Exemplo n.º 1
0
def get_table3(df):

    ### regressions:
    rslt = smf.ols(formula="stdgrade ~ treat + pol1+ pol1t",
                   data=df,
                   weights=df["kwgt"]).fit(
                       cov_type='cluster',
                       cov_kwds={'groups': df["studentid"]})
    rslt1 = rslt

    formula2 = "stdgrade ~ treat + treatmentvol + treatmentfor + volcourse + forcourse + pol1 + pol1t + pol1vol + pol1tvol + pol1for + pol1tfor"
    rslt = smf.ols(formula=formula2, data=df, weights=df["kwgt"]).fit(
        cov_type='cluster', cov_kwds={'groups': df["studentid"]})
    rslt2 = rslt

    ### Table stargazer:
    stargazer = Stargazer([rslt1, rslt2])
    stargazer.custom_columns(["column 1", "column 4"], [1, 1])
    stargazer.title("Table 3 - Effects on standardized grades")
    stargazer.show_model_numbers(False)
    stargazer.significant_digits(2)
    stargazer.covariate_order(["treat", "treatmentvol", "treatmentfor"])
    stargazer.rename_covariates({
        "treat":
        "1st-year GPA is below 7",
        "treatmentvol":
        "Attendance is voluntary x treatment",
        "treatmentfor":
        "Absence is penalized x treatment"
    })
    stargazer.show_degrees_of_freedom(False)
    stargazer.add_line('Fixed Effects', ['No', 'No'])

    return stargazer
def table10_11(df, name, democ):

    full_x = [
        f'{name}_I', f'{name}_C2', 'lnpopulation', 'lnGDP_pc', 'protestants',
        'muslims', 'catholics', 'latitude', 'LOEnglish', 'LOGerman',
        'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]
    ins = [
        f'{name}_I', f'{name}_instrument_C2_thresh', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]

    df_10_11_1 = df[[
        f'{name}_C2', f'{name}_I', f'{name}_instrument_C2_thresh',
        'lnpopulation', 'lnGDP_pc', 'protestants', 'muslims', 'catholics',
        'latitude', 'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin',
        'democ', 'mtnall', 'icrg_qog'
    ]].dropna(axis=0)
    df_10_11_2 = df[[
        f'{name}_C2', f'{name}_I', f'{name}_instrument_C2_thresh',
        'lnpopulation', 'lnGDP_pc', 'protestants', 'muslims', 'catholics',
        'latitude', 'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin',
        'democ', 'mtnall', 'ef_regul', 'ef_corruption', 'ef_property_rights'
    ]].dropna(axis=0)
    df_10_11_3 = df[[
        f'{name}_C2', f'{name}_I', f'{name}_instrument_C2_thresh',
        'lnpopulation', 'lnGDP_pc', 'protestants', 'muslims', 'catholics',
        'latitude', 'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin',
        'democ', 'mtnall', 'taxevas'
    ]].dropna(axis=0)

    if democ == 'democracy':
        df_10_11_1 = df_10_11_1[df_10_11_1.democ >= 1]
        df_10_11_2 = df_10_11_2[df_10_11_2.democ >= 1]
        df_10_11_3 = df_10_11_3[df_10_11_3.democ >= 1]

        x1 = sm.add_constant(df_10_11_1[full_x])
        x2 = sm.add_constant(df_10_11_2[full_x])
        x3 = sm.add_constant(df_10_11_3[full_x])

        ins1 = sm.add_constant(df_10_11_1[ins])
        ins2 = sm.add_constant(df_10_11_2[ins])
        ins3 = sm.add_constant(df_10_11_3[ins])

    else:
        x1 = sm.add_constant(df_10_11_1[[f'{name}_I', f'{name}_C2']])
        x2 = sm.add_constant(df_10_11_2[[f'{name}_I', f'{name}_C2']])
        x3 = sm.add_constant(df_10_11_3[[f'{name}_I', f'{name}_C2']])

        ins1 = sm.add_constant(
            df_10_11_1[[f'{name}_I', f'{name}_instrument_C2_thresh']])
        ins2 = sm.add_constant(
            df_10_11_2[[f'{name}_I', f'{name}_instrument_C2_thresh']])
        ins3 = sm.add_constant(
            df_10_11_3[[f'{name}_I', f'{name}_instrument_C2_thresh']])

    y1 = df_10_11_1['icrg_qog']
    y2 = df_10_11_2['ef_corruption']
    y3 = df_10_11_2['ef_property_rights']
    y4 = df_10_11_2['ef_regul']
    y5 = df_10_11_3['taxevas']

    est1 = sm.OLS(y1, x1).fit(cov_type='HC1')
    est2 = IV2SLS(y1, x1, ins1).fit()
    est3 = sm.OLS(y2, x2).fit(cov_type='HC1')
    est4 = IV2SLS(y2, x2, ins2).fit()
    est5 = sm.OLS(y3, x2).fit(cov_type='HC1')
    est6 = IV2SLS(y3, x2, ins2).fit()
    est7 = sm.OLS(y4, x2).fit(cov_type='HC1')
    est8 = IV2SLS(y4, x2, ins2).fit()
    est9 = sm.OLS(y5, x3).fit(cov_type='HC1')
    est10 = IV2SLS(y5, x3, ins3).fit()

    stargazer = Stargazer(
        [est1, est2, est3, est4, est5, est6, est7, est8, est9, est10])
    stargazer.custom_columns([
        'ICRG quality of gov', 'EF Corruption', 'EF Property rights',
        'EF Regulation', 'Tax eva'
    ], [2, 2, 2, 2, 2])
    stargazer.show_model_numbers(False)
    stargazer.covariate_order([f'{name}_C2', f'{name}_I'])
    stargazer.rename_covariates({
        f'{name}_C2':
        'Segregation $\hat{S}$ ('
        f'{name}'
        ')',
        f'{name}_I':
        'Fractionalization $F$ ('
        f'{name}'
        ')'
    })
    stargazer.add_line('Method', [
        'OLS', '2SLS', 'OLS', '2SLS', 'OLS', '2SLS', 'OLS', '2SLS', 'OLS',
        '2SLS'
    ])

    if democ == 'democracy':
        stargazer.title('Panel B. Democracies sample, all controls')
        return stargazer

    else:
        stargazer.title('Panel A. Full sample, no additional controls')
        return stargazer
def table6(df, alternative=True):

    df_6E = df[[
        'ethnicity_C2', 'ethnicity_I', 'ethnicity_C',
        'ethnicity_instrument_C_thresh', 'ethnicity_instrument_C2_thresh',
        'lnpopulation', 'lnGDP_pc', 'protestants', 'muslims', 'catholics',
        'latitude', 'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin',
        'democ', 'mtnall', 'RulLaw', 'country'
    ]].dropna(axis=0)
    df_6L = df[[
        'language_C2', 'language_I', 'language_C',
        'language_instrument_C_thresh', 'language_instrument_C2_thresh',
        'lnpopulation', 'lnGDP_pc', 'protestants', 'muslims', 'catholics',
        'latitude', 'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin',
        'democ', 'mtnall', 'RulLaw', 'country'
    ]].dropna(axis=0)
    df_6R = df[[
        'religion_C2', 'religion_I', 'religion_C',
        'religion_instrument_C_thresh', 'religion_instrument_C2_thresh',
        'lnpopulation', 'lnGDP_pc', 'protestants', 'muslims', 'catholics',
        'latitude', 'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin',
        'democ', 'mtnall', 'RulLaw', 'country'
    ]].dropna(axis=0)

    df_6E_demo = df_6E[df_6E.democ >= 1]
    df_6L_demo = df_6L[df_6L.democ >= 1]
    df_6R_demo = df_6R[df_6R.democ >= 1]

    x1 = sm.add_constant(df_6E[[
        'ethnicity_instrument_C2_thresh', 'ethnicity_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x2 = sm.add_constant(df_6L[[
        'language_instrument_C2_thresh', 'language_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x3 = sm.add_constant(df_6R[[
        'religion_instrument_C2_thresh', 'religion_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'democ', 'mtnall'
    ]])
    x4 = sm.add_constant(df_6E_demo[[
        'ethnicity_instrument_C2_thresh', 'ethnicity_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x5 = sm.add_constant(df_6L_demo[[
        'language_instrument_C2_thresh', 'language_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x6 = sm.add_constant(df_6R_demo[[
        'religion_instrument_C2_thresh', 'religion_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'democ', 'mtnall'
    ]])

    y1 = df_6E['ethnicity_C2']
    y2 = df_6L['language_C2']
    y3 = df_6R['religion_C2']
    y4 = df_6E_demo['ethnicity_C2']
    y5 = df_6L_demo['language_C2']
    y6 = df_6R_demo['religion_C2']

    est1 = sm.OLS(y1, x1).fit(cov_type='HC1')
    est2 = sm.OLS(y2, x2).fit(cov_type='HC1')
    est3 = sm.OLS(y3, x3).fit(cov_type='HC1')
    est4 = sm.OLS(y4, x4).fit(cov_type='HC1')
    est5 = sm.OLS(y5, x5).fit(cov_type='HC1')
    est6 = sm.OLS(y6, x6).fit(cov_type='HC1')

    x1a = sm.add_constant(df_6E[[
        'ethnicity_instrument_C_thresh', 'ethnicity_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x2a = sm.add_constant(df_6L[[
        'language_instrument_C_thresh', 'language_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x3a = sm.add_constant(df_6R[[
        'religion_instrument_C_thresh', 'religion_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'democ', 'mtnall'
    ]])
    x4a = sm.add_constant(df_6E_demo[[
        'ethnicity_instrument_C_thresh', 'ethnicity_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x5a = sm.add_constant(df_6L_demo[[
        'language_instrument_C_thresh', 'language_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]])
    x6a = sm.add_constant(df_6R_demo[[
        'religion_instrument_C_thresh', 'religion_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'democ', 'mtnall'
    ]])

    y1a = df_6E['ethnicity_C']
    y2a = df_6L['language_C']
    y3a = df_6R['religion_C']
    y4a = df_6E_demo['ethnicity_C']
    y5a = df_6L_demo['language_C']
    y6a = df_6R_demo['religion_C']

    est1a = sm.OLS(y1a, x1a).fit(cov_type='HC1')
    est2a = sm.OLS(y2a, x2a).fit(cov_type='HC1')
    est3a = sm.OLS(y3a, x3a).fit(cov_type='HC1')
    est4a = sm.OLS(y4a, x4a).fit(cov_type='HC1')
    est5a = sm.OLS(y5a, x5a).fit(cov_type='HC1')
    est6a = sm.OLS(y6a, x6a).fit(cov_type='HC1')

    df_6Lb = df_6L.set_index('country')
    df_6Lb_demo = df_6L_demo.set_index('country')

    x2b = sm.add_constant(df_6Lb[[
        'language_instrument_C_thresh', 'language_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]].drop(index='usa'))

    x5b = sm.add_constant(df_6Lb_demo[[
        'language_instrument_C_thresh', 'language_I', 'lnpopulation',
        'lnGDP_pc', 'protestants', 'muslims', 'catholics', 'latitude',
        'LOEnglish', 'LOGerman', 'LOSocialist', 'LOScandin', 'democ', 'mtnall'
    ]].drop(index='usa'))
    y2b = df_6Lb['language_C'].drop(index='usa')
    y5b = df_6Lb_demo['language_C'].drop(index='usa')

    est2b = sm.OLS(y2b, x2b).fit(cov_type='HC1')
    est5b = sm.OLS(y5b, x5b).fit(cov_type='HC1')

    stargazer = Stargazer([est1, est2, est3, est4, est5, est6])
    stargazer_a = Stargazer([est1a, est2a, est3a, est4a, est5a, est6a])
    stargazer_b = Stargazer([est2b, est5b])

    stargazer.covariate_order([
        'ethnicity_instrument_C2_thresh', 'ethnicity_I',
        'language_instrument_C2_thresh', 'language_I',
        'religion_instrument_C2_thresh', 'religion_I'
    ])
    stargazer.rename_covariates({
        'ethnicity_instrument_C2_thresh': 'Instrument E',
        'ethnicity_I': '$F$ (ethnicity)',
        'language_instrument_C2_thresh': 'Instrument L',
        'language_I': '$F$ (language)',
        'religion_instrument_C2_thresh': 'Instrument R',
        'religion_I': '$F$ (religion)'
    })
    stargazer.custom_columns([
        'E$\hat{S}$', 'L$\hat{S}$', 'R$\hat{S}$', 'E$\hat{S}$', 'L$\hat{S}$',
        'R$\hat{S}$'
    ], [1, 1, 1, 1, 1, 1])
    stargazer.show_model_numbers(False)
    stargazer.add_line(
        'Sample',
        ['Full', 'Full', 'Full', 'Democracy', 'Democracy', 'Democracy'])
    stargazer.title('Panel A. Segregation index $\hat{S}$')

    stargazer_a.covariate_order([
        'ethnicity_instrument_C_thresh', 'ethnicity_I',
        'language_instrument_C_thresh', 'language_I',
        'religion_instrument_C_thresh', 'religion_I'
    ])
    stargazer_a.rename_covariates({
        'ethnicity_instrument_C_thresh': 'Instrument E',
        'ethnicity_I': '$F$ (ethnicity)',
        'language_instrument_C_thresh': 'Instrument L',
        'language_I': '$F$ (language)',
        'religion_instrument_C_thresh': 'Instrument R',
        'religion_I': '$F$ (religion)'
    })
    stargazer_a.custom_columns([
        'E$\\tilde{S}$', 'L$\\tilde{S}$', 'R$\\tilde{S}$', 'E$\\tilde{S}$',
        'L$\\tilde{S}$', 'R$\\tilde{S}$'
    ], [1, 1, 1, 1, 1, 1])
    stargazer_a.show_model_numbers(False)
    stargazer_a.add_line(
        'Sample',
        ['Full', 'Full', 'Full', 'Democracy', 'Democracy', 'Democracy'])
    stargazer_a.title('Panel B. Segregation index $\\tilde{S}$')

    stargazer_b.covariate_order(['language_instrument_C_thresh', 'language_I'])
    stargazer_b.rename_covariates({
        'language_instrument_C_thresh': 'Instrument L',
        'language_I': '$F$ (language)'
    })
    stargazer_b.custom_columns(['L$\\tilde{S}$', 'L$\\tilde{S}$'], [1, 1])
    stargazer_b.show_model_numbers(False)
    stargazer_b.add_line('Sample', ['Full', 'Democracy'])
    stargazer_b.title(
        'Panel C. Segregation index $\\tilde{S}$ for language with sample excluding the US'
    )

    return [stargazer, stargazer_a, stargazer_b]