Ejemplo n.º 1
0
    def test_match(self):
        matcher = PropensityScoreMatching()
        X = pd.DataFrame({'assignment': [1, 0, 0, 0, 0, 0],
                          'propensity score': [3, 1, 2, 3, 5, 4]})

        test, control = matcher.match(X, n_neighbors=3)
        assert set(control['propensity score'].values) == set([2, 3, 4])
Ejemplo n.º 2
0
    def test_match(self):
        matcher = PropensityScoreMatching()
        X = pd.DataFrame({
            'assignment': [1, 0, 0, 0, 0, 0],
            'propensity score': [3, 1, 2, 3, 5, 4]
        })

        test, control = matcher.match(X, n_neighbors=3)
        assert set(control['propensity score'].values) == set([2, 3, 4])
Ejemplo n.º 3
0
    def test_match(self):
        matcher = PropensityScoreMatching()
        X = pd.DataFrame(
            {"assignment": [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], "propensity score": [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]}
        )

        test, control = matcher.match(X, n_neighbors=3)

        matches = test[test["propensity score"] == 2]["matches"].values[0][0]
        assert set(control.iloc[matches]["propensity score"].values) == set([1, 2, 3])

        matches = test[test["propensity score"] == 4]["matches"].values[0][0]
        assert set(control.iloc[matches]["propensity score"].values) == set([3, 4, 5])
Ejemplo n.º 4
0
    def test_match(self):
        matcher = PropensityScoreMatching()
        X = pd.DataFrame({
            'assignment': [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
            'propensity score': [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
        })

        test, control = matcher.match(X, n_neighbors=3)

        matches = test[test['propensity score'] == 2]['matches'].values[0][0]
        assert set(control.iloc[matches]['propensity score'].values) == set(
            [1, 2, 3])

        matches = test[test['propensity score'] == 4]['matches'].values[0][0]
        assert set(control.iloc[matches]['propensity score'].values) == set(
            [3, 4, 5])
Ejemplo n.º 5
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")