USW-Tax-Analyzer

Using the API
Login

Writing Python Applications that Import the USW-Tax-Analyzer Package

Here we show how to use the uswtaxanalyzer package in a Python application that computes the change in aggregate wealth tax liability caused by the reform discussed in the CLI documentation section entitled Comparing No-Avoidance Results. The Python application produces the same results, but only after some time spent writing the Python code. Python applications that undertake non-static analysis (such as avoidance responses to the reform) are considerably more complex than the example presented here.

Here is the Python code, which has been composed in a text editor and saved in the app.py file:

$ tacat app.py
"""
This USW-Tax-Analyzer application produces the same 2019 aggregate wealth
tax liability estimates as produced by the CLI example in the documentation
under the assumption of no avoidance response to the reform.
"""

import uswtaxanalyzer as ta

cyr = 2019

pol = ta.Policy()  # represents current-law policy (that is, no wealth tax)
rec = ta.Records()  # uses built-in data, weights, and default growth factors

# create Calculator object for current-law policy and calculate tax liability
calc1 = ta.Calculator(policy=pol, records=rec)
# the calc1 object contains private copies of pol and rec,
# so we are free to use pol and rec however we want below
calc1.advance_to_year(cyr)
calc1.calculate()
dframe1 = calc1.dataframe(['wtax', 'weight'])
del calc1
wtax1 = (dframe1.wtax * dframe1.weight).sum()

# create Calculator object for reform policy and calculate tax liability
# specify Warren reform used in the CLI example as a Python dictionary
# rather than as the JSON text in the ew.json file used by the CLI
ref = {
    # 1st is a zero rate bracket for wealth up to $50 million
    'brak1': {2019: 50e6}, 'rate1': {2019: 0.00},
    # 2nd is a 2% rate bracket from $50 million to $1 billion
    'brak2': {2019:  1e9}, 'rate2': {2019: 0.02},
    # 3rd is a 3% rate bracket for wealth over $1 billion
    'brak3': {2019: 9e99}, 'rate3': {2019: 0.03}
}
pol.implement_reform(ref)
calc2 = ta.Calculator(policy=pol, records=rec)
calc2.advance_to_year(cyr)
calc2.calculate()
dframe2 = calc2.dataframe(['wtax', 'weight'])
del calc2
wtax2 = (dframe2.wtax * dframe2.weight).sum()
ntaxed = dframe2[dframe2.wtax > 0].weight.sum()

print(f'{cyr} CurLaw WTax Liability ($b) = {(wtax1 * 1e-9):.1f}')
print(f'{cyr} Reform WTax Liability ($b) = {(wtax2 * 1e-9):.1f}')
print(f'Number of households taxed (#) = {ntaxed:.0f}')

When this application is executed at the command prompt, it produces these results:

$ python app.py
2019 CurLaw WTax Liability ($b) = 0.0
2019 Reform WTax Liability ($b) = 254.7
Number of households taxed (#) = 93895

These results are the same as generated by this CLI run and dump output tabulation:

$ uswta tax.csv 2019 ew.json && awk -f opa.awk tax-19-ew.csv
INPUT data are extrapolated to 2019 using default growth factors under CurLaw
INPUT data are extrapolated to 2019 using default growth factors under REFORM
Calculations for 2019 use no response elasticities
Write minimal REFORM dump output file ./tax-19-ew.csv for 2019
Write table output file ./tax-19-ew.tab for 2019
Write REFORM parameter output file ./tax-19-ew.par for 2019
Run time is 0.1 seconds
BITSS-OPA-style results for 2019
total_wealth_tax_($b)= 254.7
total_households_(#m)= 156.436
taxed_households_(#)= 93895
percent_hhs_taxed(%)= 0.06