-
Notifications
You must be signed in to change notification settings - Fork 59
/
app00.py
143 lines (131 loc) · 5.74 KB
/
app00.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
**Basic app for CIT Microsimulation**
app00.py illustrates use of TPRU-India taxcalc release 2.0.0
USAGE: python app00.py > app00.res
CHECK: Use your favorite Windows diff utility to confirm that app00.res is
the same as the app00.out file that is in the repository.
"""
import pandas as pd
from taxcalc import *
# create Records object containing pit.csv and pit_weights.csv input data
recs = Records()
grecs = GSTRecords()
# create CorpRecords object using cross-section data
crecs1 = CorpRecords(data='cit_cross.csv', weights='cit_cross_wgts.csv')
# Note: weights argument is optional
assert isinstance(crecs1, CorpRecords)
assert crecs1.current_year == 2017
# create CorpRecords object using panel data
crecs2 = CorpRecords(data='cit_panel.csv', data_type='panel')
assert isinstance(crecs2, CorpRecords)
assert crecs2.current_year == 2017
# create Policy object containing current-law policy
pol = Policy()
# specify Calculator objects for current-law policy
calc1 = Calculator(policy=pol, records=recs, corprecords=crecs1,
gstrecords=grecs, verbose=False)
calc2 = Calculator(policy=pol, records=recs, corprecords=crecs2,
gstrecords=grecs, verbose=False)
# NOTE: calc1 now contains a PRIVATE COPY of pol and a PRIVATE COPY of recs,
# so we can continue to use pol and recs in this script without any
# concern about side effects from Calculator method calls on calc1.
assert isinstance(calc1, Calculator)
assert calc1.current_year == 2017
assert isinstance(calc2, Calculator)
assert calc2.current_year == 2017
# Produce DataFrame of results using cross-section
calc1.calc_all()
# AggInc17c = calc1.carray('GTI_Before_Loss')
# Losses17c = calc1.carray('CY_Losses')
GTI17c = calc1.carray('GTI')
citax17c = calc1.carray('citax')
citax17c_with_MAT = calc1.carray('citax_after_MAT')
wgt17c = calc1.carray('weight')
calc1.increment_year()
calc1.calc_all()
GTI18c = calc1.carray('GTI')
citax18c = calc1.carray('citax')
citax18c_with_MAT = calc1.carray('citax_after_MAT')
wgt18c = calc1.carray('weight')
results_cross = pd.DataFrame({'GTI2017': GTI17c,
'citax2017': citax17c,
'GTI2018': GTI18c,
'citax2018': citax18c})
results_cross.to_csv('app00-dump-crosssection.csv', index=False,
float_format='%.0f')
# Produce DataFFrame of results using panel
# First do 2017
calc2.calc_all()
# AggInc17p = calc1.carray('GTI_Before_Loss')
# Losses17p = calc1.carray('CY_Losses')
GTI17p = calc2.carray('GTI')
citax17p = calc2.carray('citax')
citax17p_with_MAT = calc2.carray('citax_after_MAT')
id17p = calc2.carray('ID_NO')
wgt17p = calc2.carray('weight')
results_panel17 = pd.DataFrame({'ID_NO': id17p,
'GTI2017': GTI17p,
'citax2017': citax17p})
# Then do 2018
calc2.increment_year()
calc2.calc_all()
GTI18p = calc2.carray('GTI')
citax18p = calc2.carray('citax')
citax18p_with_MAT = calc2.carray('citax_after_MAT')
id18p = calc2.carray('ID_NO')
wgt18p = calc2.carray('weight')
results_panel18 = pd.DataFrame({'ID_NO': id18p,
'GTI2018': GTI18p,
'citax2018': citax18p})
# Merge them together
results_panel = results_panel17.merge(right=results_panel18, how='outer',
on='ID_NO')
results_panel.drop(['ID_NO'], axis=1, inplace=True)
results_panel.to_csv('app00-dump-panel.csv', index=False, float_format='%.0f')
# Print results
print('**************** Assessment Year 2017-18 ****************')
print(f'Number of Taxpayers:', end=' ')
print(f'{sum(wgt17c):,.0f}')
print(f'Total GTI (in Cr.), cross-section:', end=' ')
print(f'{sum(GTI17c * wgt17c) * 1e-7:,.2f}')
print(f'Total tax liability (in Cr.), cross-section:', end=' ')
print(f'{sum(citax17c * wgt17c) * 1e-7:,.2f}')
print(f'Total tax liability with MAT (in Cr.), cross-section:', end=' ')
print(f'{sum(citax17c_with_MAT * wgt17c) * 1e-7:,.2f}')
print(f'Tax rate, cross-section:', end=' ')
print(f'{sum(citax17c * wgt17c)/sum(GTI17c * wgt17c):,.2f}')
print('\n')
print(f'Total GTI (in Cr.), panel:', end=' ')
print(f'{sum(GTI17p * wgt17p) * 1e-7:,.2f}')
print(f'Total tax liability (in Cr.), panel:', end=' ')
print(f'{sum(citax17p * wgt17p) * 1e-7:,.2f}')
print(f'Total tax liability with MAT (in Cr.), panel:', end=' ')
print(f'{sum(citax17p_with_MAT * wgt17p) * 1e-7:,.2f}')
print(f'Tax rate, panel:', end=' ')
print(f'{sum(citax17p * wgt17p)/sum(GTI17p * wgt17p):,.2f}')
print('\n')
print('**************** Assessment Year 2018-19 ****************')
print(f'Number of Taxpayers:', end=' ')
print(f'{sum(wgt18c):,.0f}')
print(f'Total GTI (in Cr.), cross-section:', end=' ')
print(f'{sum(GTI18c * wgt18c) * 1e-7:,.2f}')
print(f'Total tax liability (in Cr.), cross-section:', end=' ')
print(f'{sum(citax18c * wgt18c) * 1e-7:,.2f}')
print(f'Total tax liability with MAT (in Cr.), cross-section:', end=' ')
print(f'{sum(citax18c_with_MAT * wgt18c) * 1e-7:,.2f}')
print(f'Tax rate, cross-section:', end=' ')
print(f'{sum(citax18c * wgt18c)/sum(GTI18c * wgt18c):,.2f}')
print('\n')
print(f'Total GTI (in Cr.), panel:', end=' ')
print(f'{sum(GTI18p * wgt18p) * 1e-7:,.2f}')
print(f'Total tax liability (in Cr.), panel:', end=' ')
print(f'{sum(citax18p * wgt18p) * 1e-7:,.2f}')
print(f'Total tax liability with MAT (in Cr.), panel:', end=' ')
print(f'{sum(citax18p_with_MAT * wgt18p) * 1e-7:,.2f}')
print(f'Tax rate, panel:', end=' ')
print(f'{sum(citax18p * wgt18p)/sum(GTI18p * wgt18p):,.2f}')
print('**************** ****************\n')
print(f'Average liabilit (in Lakh), 2017, cross-section:', end=' ')
print(f'{sum(citax17c * wgt17c) * 1e-5 / sum(wgt17c):,.2f}')
print(f'Average liabilit (in Lakh), 2017, panel:', end=' ')
print(f'{sum(citax17p * wgt17p) * 1e-5 / sum(wgt17p):,.2f}')