Пример #1
0
def spx_wmOnBoard_tobin():
    '''
    Test the effect of having women on the board of directors on the tobins Q score
    M&M:
        For the American companies inside the S&P 500 index,
        we found a positive correlation between the percentage higher
        than 20 % of women in the board and the Tobin’s Q ratio
    Latest Results:
        (-0.094388682158789469, -0.04962212239013655, -0.0068850052276448973)
    Comments:
        So no real causal influence here, wrong sign
    '''
    data, types = getData("spx_fboard","corp_gov_causal")
    controlFor = stageAlgo(types)
    treatment = 'X..Women.on.Bd'
    target = 'Tobins.Q'

    matcher = PropensityScoreMatching()
    ATE_results = matcher.estimate_ATE(data, treatment, target, {'P.EBITDA': 'c', 'P.B': 'c', 'Asset':'c', 'Tax':'c', 'P.E':'c'}, bootstrap=True)

    matcher.check_support(data, 'X..Women.on.Bd', {'P.EBITDA': 'c', 'P.B': 'c','Asset':'c', 'Tax':'c', 'P.E':'c'})

    print("")
    print("Balance before matching")
    print(matcher.assess_balance(data, 'X..Women.on.Bd', {'P.EBITDA': 'c', 'P.B': 'c','Asset':'c', 'Tax':'c', 'P.E':'c', 'propensity score': 'c'}))
    print ("")

    data = matcher.score(data, assignment='X..Women.on.Bd', confounder_types={'P.EBITDA': 'c', 'P.B': 'c','Asset':'c', 'Tax':'c', 'P.E':'c'})
    treated, control = matcher.match(data, assignment='X..Women.on.Bd')
    print("")
    print("Balance after matching")
    print(matcher.assess_balance(treated.append(control), 'X..Women.on.Bd', {'P.EBITDA': 'c', 'P.B': 'c','Asset':'c', 'Tax':'c', 'P.E':'c', 'propensity score': 'c'}))
    print ("")

    #now write results to mysql
    conn = MySQLdb.connect(host="localhost",
                         user="******",
                         passwd="",
                         db="causal_results")
    cur = conn.cursor()
    query = """ insert into akelleh_results values ('%s','%s','%s','%s','%s','%s');  """ % (now,"spx",treatment,target,str(ATE_results),"For the American companies inside the S and P 500 index, we found a positive correlation between the percentage higher than 20pct of women in the board and the Tobins Q ratio")
    cur.execute(query)
    conn.commit()
    conn.close()
    print("Done")
Пример #2
0
import pandas as pd
import numpy as np
from causality.estimation.parametric import PropensityScoreMatching

N = 10000
z1 = np.random.normal(size=N)
z2 = np.random.normal(size=N)
z3 = np.random.normal(size=N)

p_d = 1. / (1. + np.exp(-(z1 + z2 + z3)/4.))
d = np.random.binomial(1, p=p_d)

y0 = np.random.normal()
y1 = y0 + z1 + z2 + z3

y = (d==1)*y1 + (d==0)*y0
X = pd.DataFrame({'d': d, 'z1': z1, 'z2': z2, 'z3': z3, 'y': y, 'y0': y0, 'y1': y1, 'p': p_d})

print(X.head(10))

matcher = PropensityScoreMatching()
print(matcher.estimate_ATE(X, 'd', 'y', {'z1': 'c', 'z2': 'c', 'z3': 'c'}))

matcher.check_support(X, 'd', {'z1': 'c', 'z2': 'c', 'z3': 'c'})

print(matcher.assess_balance(X, 'd', {'z1': 'c', 'z2': 'c', 'z3': 'c'}))