-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp1_class_1.py
More file actions
127 lines (106 loc) · 4.73 KB
/
app1_class_1.py
File metadata and controls
127 lines (106 loc) · 4.73 KB
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
"""
app1.py illustrates use of pitaxcalc-demo release 2.0.0 (India version).
USAGE: python app1.py > app1.res
CHECK: Use your favorite Windows diff utility to confirm that app1.res is
the same as the app1.out file that is in the repository.
"""
import json
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Initialize the variables
vars = {}
vars['pit'] = 1
vars['cit'] = 0
vars['vat'] = 0
tax_type = 'pit'
vars['DEFAULTS_FILENAME'] = "current_law_policy_vat_indo.json"
vars['GROWFACTORS_FILENAME'] = "growfactors_vat_indo.csv"
vars['pit_data_filename'] = "C:/Users/adeda/Microsimulation/Tax_Microsimulation/taxcalc/vat_sample_indo.csv"
vars['pit_weights_filename'] = "C:/Users/adeda/Microsimulation/Tax_Microsimulation/taxcalc/vat_sample_indo_weights.csv"
vars['pit_records_variables_filename'] = "records_variables_vat_indo.json"
vars['pit_benchmark_filename'] = "tax_incentives_benchmark_pit_training.json"
vars['pit_elasticity_filename'] = "elasticity_pit_training.json"
vars['pit_functions_filename'] = "functions_vat_indo.py"
vars['pit_function_names_filename'] = "function_names_vat_indo.json"
vars['pit_distribution_json_filename'] = 'vat_distribution_indo.json'
vars['vat_data_filename'] = "gst.csv"
vars['vat_weights_filename'] = "gst_weights.csv"
vars['vat_records_variables_filename'] = "gstrecords_variables.json"
vars['cit_data_filename'] = "cit_cross.csv"
vars['cit_weights_filename'] = "cit_cross_wgts1.csv"
vars['cit_records_variables_filename'] = "corprecords_variables.json"
vars['gdp_filename'] = 'gdp_nominal_training.csv'
vars["start_year"] = 2022
vars["end_year"] = 2027
vars["SALARY_VARIABLE"] = "CONS_total"
vars['elasticity_filename'] = "elasticity_pit_training.json"
vars['DIST_VARIABLES'] = ['weight', 'CONS_total', 'vat']
vars['DIST_TABLE_COLUMNS'] = ['weight', 'CONS_total', 'vat']
vars['DIST_TABLE_LABELS'] = ['Population',
'Total Consumption',
'VAT']
vars['DECILE_ROW_NAMES'] = ['0-10n', '0-10z', '0-10p',
'10-20', '20-30', '30-40', '40-50',
'50-60', '60-70', '70-80', '80-90', '90-100',
'ALL',
'90-95', '95-99', 'Top 1%']
vars['STANDARD_ROW_NAMES'] = [ "<0", "=0", "0-0.5 m", "0.5-1m", "1-1.5m", "1.5-2m",
"2-3m", "3-4m", "4-5m", "5-10m", ">10m", "ALL"]
vars['STANDARD_INCOME_BINS'] = [-9e99, -1e-9, 1e-9, 5e5, 10e5, 15e5, 20e5, 30e5,
40e5, 50e5, 100e5, 9e99]
vars['income_measure'] = "total_gross_income"
vars['show_error_log'] = 0
vars['verbose'] = 0
vars['data_start_year'] = 2018
f = open('C:/Users/adeda/Microsimulation/Tax_Microsimulation/taxcalc/'+vars['pit_distribution_json_filename'])
distribution_vardict_dict = json.load(f)
f.close()
#print(distribution_vardict_dict)
with open('global_vars.json', 'w') as f:
f.write(json.dumps(vars, indent=2))
f.close()
from taxcalc import *
# create Records object containing pit.csv and pit_weights.csv input data
recs = Records()
# create Policy object containing current-law policy
pol = Policy()
# specify Calculator object for current-law policy
calc1 = Calculator(policy=pol, records=recs, verbose=False)
calc1.calc_all()
# specify Calculator object for reform in JSON file
reform = Calculator.read_json_param_objects('app0_reform_vat_indo.json', None)
pol.implement_reform(reform['policy'])
calc2 = Calculator(policy=pol, records=recs, verbose=False)
calc2.calc_all()
# compare aggregate results from two calculators
weighted_tax1 = calc1.weighted_total_pit('vat')
weighted_tax2 = calc2.weighted_total_pit('vat')
total_weights = calc1.total_weight_pit()
print(f'Tax 1 {weighted_tax1 * 1e-9:,.2f}')
print(f'Tax 2 {weighted_tax2 * 1e-9:,.2f}')
print(f'Total weight {total_weights * 1e-6:,.2f}')
calc1.advance_to_year(2022)
calc2.advance_to_year(2022)
calc1.calc_all(2022)
calc2.calc_all(2022)
# dump out records
dump_vars = ['id_n', 'Year', 'CONS_total', 'vat_food', 'vat_non_food', 'vat', 'vat1', 'vat2']
dumpdf = calc1.dataframe(dump_vars)
dumpdf['pitax1'] = calc1.array('pitax')
dumpdf['pitax2'] = calc2.array('pitax')
dumpdf['pitax_diff'] = dumpdf['pitax2'] - dumpdf['pitax1']
column_order = dumpdf.columns
dumpdf.to_csv('app1-dump.csv', columns=column_order,
index=False, float_format='%.0f')
def calc_gini(income, sort=None):
n = len(income)
#cumulative_income = np.cumsum(income)
cumulative_income= income.sum()
gini_index = ((2 * np.sum((np.arange(1, n + 1) * income))) / (n *
cumulative_income[-1])) - ((n + 1) / n)
return gini_index
gini_pre = calc_gini(dumpdf['pitax1'])
print(gini_pre)
gini_post=calc_gini(dumpdf['pitax2'])
print(gini_post)