Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Increases independence of substitution effects #44

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

MattHJensen
Copy link
Contributor

This resolves the lack of independence between the substitution effect and the long term capital gains elasticity identified by @martinholmer in #41.

@codecov-io
Copy link

codecov-io commented Feb 20, 2019

Codecov Report

Merging #44 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #44   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         112    112           
=====================================
  Hits          112    112
Impacted Files Coverage Δ
behresp/behavior.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df35a9d...760b2c4. Read the comment docs.

@martinholmer
Copy link
Collaborator

martinholmer commented Feb 20, 2019

@MattHJensen, Thanks for the enhancement in B-R PR #44. The new test records are good. But your original thought was that short-term capital gains/losses would complicate the calculation of the the largest long-term capital loss that could be used in the new adjustment. If you specify each of the five test cases to have $9000 in short-term capital gains, then the independence test fails for RECIDs 3, 4, and 5. Here are the alternative test cases:

    input_csv = (u'RECID,MARS,e00200,e00200p,p23250,p22250\n'
                 u'1,1,1000000,1000000,0     ,9000\n'
                 u'2,1,1000000,1000000,500000,9000\n'
                 u'3,1,1000000,1000000,-50000,9000\n'
                 u'4,3,1000000,1000000,-50000,9000\n'
                 u'5,1,1000000,1000000,-10000,9000\n')

@martinholmer
Copy link
Collaborator

@MattHJensen, Your original notion that the amount of short-term capital gains would complicate the long-term capital loss adjustment is correct. The adjustment I suggested is not correct. A stronger test shows that my suggestion is incorrect. I suggest you copy and paste the revised test (see below) into your PR branch and then figure out what adjustment formula allows you to pass all the tests. You can run the tests quickly using this command: cd behresp ; pytest -m one -n4 ; cd ..
Here is the revised test:

@pytest.mark.one
@pytest.mark.parametrize("stcg",
                         [-3600,
                          -2400,
                          -1200,
                          0,
                          1200,
                          2400,
                          3600,
                          4800])
def test_sub_effect_independence(stcg):
    """
    Ensure that LTCG amount does not affect magnitude of substitution effect.
    """
    # specify reform that raises top-bracket marginal tax rate
    refyear = 2020
    reform = {refyear: {'_II_rt7': [0.70]}}
    # specify a substitution effect behavioral response
    beh_json = """{
    "BE_sub": {"2013": 0.25}
    }"""
    # specify several high-earning filing units
    num_recs = 9
    input_csv = (u'RECID,MARS,e00200,e00200p,p22250,p23250\n'
                 u'1,2,1000000,1000000,stcg,    0\n'
                 u'2,2,1000000,1000000,stcg, 4800\n'
                 u'3,2,1000000,1000000,stcg, 3600\n'
                 u'4,2,1000000,1000000,stcg, 2400\n'
                 u'5,2,1000000,1000000,stcg, 1200\n'
                 u'6,2,1000000,1000000,stcg,    0\n'
                 u'7,2,1000000,1000000,stcg,-1200\n'
                 u'8,2,1000000,1000000,stcg,-2400\n'
                 u'9,2,1000000,1000000,stcg,-3600\n')
    inputcsv = input_csv.replace('stcg', str(stcg))
    input_dataframe = pd.read_csv(StringIO(inputcsv))
    assert len(input_dataframe.index) == num_recs
    recs = tc.Records(data=input_dataframe,
                      start_year=refyear,
                      gfactors=None, weights=None)
    beh_dict = tc.Calculator.read_json_assumptions(beh_json)
    pol = tc.Policy()
    calc1 = tc.Calculator(records=recs, policy=pol)
    assert calc1.current_year == refyear
    pol.implement_reform(reform)
    calc2 = tc.Calculator(records=recs, policy=pol)
    assert calc2.current_year == refyear
    del pol
    df1, df2 = response(calc1, calc2, beh_dict)
    del calc1
    del calc2
    # compute change in taxable income for each of the filing units
    chg_funit = dict()
    for rid in range(1, num_recs + 1):
        idx = rid - 1
        chg_funit[rid] = df2['c04800'][idx] - df1['c04800'][idx]
    del df1
    del df2
    # confirm reform reduces taxable income when assuming substitution effect
    emsg = ''
    for rid in range(1, num_recs + 1):
        if not chg_funit[rid] < 0:
            txt = '\nFAIL: stcg={} : chg[{}]={:.2f} is not negative'
            emsg += txt.format(stcg, rid, chg_funit[rid])
    # confirm change in taxable income is same for all filing units
    for rid in range(2, num_recs + 1):
        if not np.allclose(chg_funit[rid], chg_funit[1]):
            txt = '\nFAIL: stcg={} : chg[{}]={:.2f} != chg[1]={:.2f}'
            emsg += txt.format(stcg, rid, chg_funit[rid], chg_funit[1])
    del chg_funit
    if emsg:
        raise ValueError(emsg)

@MattHJensen MattHJensen removed the WIP label Aug 6, 2020
@MattHJensen MattHJensen changed the title Increases independence of substitution effects [WIP] Increases independence of substitution effects Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants