-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
recipe03.py.html
45 lines (39 loc) · 1.44 KB
/
recipe03.py.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<title>recipe03.py</title><pre>
from taxcalc import *
# use publicly-available CPS input file
recs = Records.cps_constructor()
# specify Calculator object for static analysis of current-law policy
pol = Policy()
calc = Calculator(policy=pol, records=recs)
cyr = 2020
# calculate aggregate current-law income tax liabilities for cyr
calc.advance_to_year(cyr)
calc.calc_all()
# tabulate custom table showing number of filing units receiving EITC
# and the average positive EITC amount by IRS-SOI AGI categories
vardf = calc.dataframe(['s006', 'c00100', 'eitc'])
vardf = add_income_table_row_variable(vardf, 'c00100', SOI_AGI_BINS)
gbydf = vardf.groupby('table_row', as_index=False)
# print AGI table with ALL row at bottom
print('Filing Units Receiving EITC and Average Positive EITC by AGI Category')
results = '{:23s}\t{:8.3f}\t{:8.3f}'
colhead = '{:23s}\t{:>8s}\t{:>8s}'
print(colhead.format('AGI Category', 'Num(#M)', 'Avg($K)'))
tot_recips = 0.
tot_amount = 0.
idx = 0
for grp_interval, grp in gbydf:
recips = grp[grp['eitc'] > 0]['s006'].sum() * 1e-6
tot_recips += recips
amount = (grp['eitc'] * grp['s006']).sum() * 1e-9
tot_amount += amount
if recips > 0:
avg = amount / recips
else:
avg = np.nan
glabel = '[{:.8g}, {:.8g})'.format(grp_interval.left, grp_interval.right)
print(results.format(glabel, recips, avg))
idx += 1
avg = tot_amount / tot_recips
print(results.format('ALL', tot_recips, avg))
</pre>