Skip to content

Commit

Permalink
Prep for Sri Lanka CIT Training
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiansajie committed Aug 15, 2022
1 parent 69ec7b6 commit b8b21fa
Show file tree
Hide file tree
Showing 8 changed files with 4,085 additions and 4,064 deletions.
190 changes: 95 additions & 95 deletions cit_etr.csv

Large diffs are not rendered by default.

29 changes: 22 additions & 7 deletions generate_policy_revenues.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,23 @@ def generate_policy_revenues():
tax_collection_var_list = tax_collection_var_list + ['pitax']
id_varlist = id_varlist + [global_variables['pit_id_var']]
recs = Records(data=global_variables['pit_data_filename'], weights=global_variables['pit_weights_filename'], gfactors=GrowFactors(growfactors_filename=global_variables['GROWFACTORS_FILENAME']))
tax_collection_var = 'pitax'
else:
recs = None
if global_variables['cit']:
tax_list = tax_list + ['cit']
tax_collection_var_list = tax_collection_var_list + ['citax']
id_varlist = id_varlist + [global_variables['cit_id_var']]
crecs = CorpRecords(data=global_variables['cit_data_filename'], weights=global_variables['cit_weights_filename'], gfactors=GrowFactors(growfactors_filename=global_variables['GROWFACTORS_FILENAME']))
tax_collection_var = 'citax'
else:
crecs = None
if global_variables['vat']:
tax_list = tax_list + ['vat']
tax_collection_var_list = tax_collection_var_list + ['vatax']
id_varlist = id_varlist + [global_variables['vat_id_var']]
grecs = GSTRecords(data=global_variables['vat_data_filename'], weights=global_variables['vat_weights_filename'], gfactors=GrowFactors(growfactors_filename=global_variables['GROWFACTORS_FILENAME']))
tax_collection_var = 'vatax'
else:
grecs = None

Expand Down Expand Up @@ -199,7 +202,7 @@ def generate_policy_revenues():
pol2.implement_reform(reform['policy'])
calc2 = Calculator(policy=pol2, records=recs, corprecords=crecs, gstrecords=grecs, verbose=verbose)

tax_collection_var = tax_collection_var_list[0]
#tax_collection_var = tax_collection_var_list[0]
id_var = id_varlist[0]

if adjust_behavior:
Expand Down Expand Up @@ -372,19 +375,30 @@ def generate_policy_revenues():
averages=output_in_averages,
scaling=True, attribute_var=dist_table_attribute_var)

df_tax1[tax_type][year]['All'] = calc1.dataframe([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax1[tax_type][year]['All'].set_index(id_var)
df_tax2[tax_type][year]['All'] = calc2.dataframe([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax2[tax_type][year]['All'].set_index(id_var)
if tax_type=='pit':
df_tax1[tax_type][year]['All'] = calc1.dataframe([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax1[tax_type][year]['All'].set_index(id_var)
df_tax2[tax_type][year]['All'] = calc2.dataframe([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax2[tax_type][year]['All'].set_index(id_var)
elif tax_type=='cit':
df_tax1[tax_type][year]['All'] = calc1.dataframe_cit([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax1[tax_type][year]['All'].set_index(id_var)
df_tax2[tax_type][year]['All'] = calc2.dataframe_cit([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax2[tax_type][year]['All'].set_index(id_var)
elif tax_type=='vat':
df_tax1[tax_type][year]['All'] = calc1.dataframe_vat([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax1[tax_type][year]['All'].set_index(id_var)
df_tax2[tax_type][year]['All'] = calc2.dataframe_vat([id_var, 'weight', income_measure[tax_type], tax_collection_var])
df_tax2[tax_type][year]['All'].set_index(id_var)
#print('dt1_percentile[tax_type][year] ', dt1_percentile[tax_type][year])
#print('dt1 ',dt1)

def calc_gini(df_tax12, tax_type):
"""
Return gini.
"""
#print('df_tax12[tax_type] ', df_tax12[tax_type]['All'])
df_tax12[tax_type]['All']['weight'] = df_tax12[tax_type]['All']['weight'+'_'+str(start_year)]

df_tax12[tax_type]['All']['weight'] = df_tax12[tax_type]['All']['weight'+'_'+str(start_year)]
df_tax12[tax_type]['All']['pre_tax_income'] = df_tax12[tax_type]['All'][income_measure[tax_type]+'_'+str(start_year)]
df_tax12[tax_type]['All']['after_tax_income'] = (df_tax12[tax_type]['All'][income_measure[tax_type]+'_'+str(start_year)]-
df_tax12[tax_type]['All'][tax_collection_var+'_'+str(start_year)])
Expand Down Expand Up @@ -508,6 +522,7 @@ def display_distribution_table_window(tax_type):
dt12={}
dt34={}
for tax_type in tax_list:

df_tax12[tax_type] = merge_distribution_table_dicts(df_tax1, df_tax2, tax_type, data_start_year, end_year)
dt12[tax_type] = merge_distribution_table_dicts(dt1, dt2, tax_type, data_start_year, end_year)
dt34[tax_type] = merge_distribution_table_dicts(dt3, dt4, tax_type, data_start_year, end_year)
Expand Down
14 changes: 8 additions & 6 deletions gui_tab1.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def initialize_vars(self):
self.vars['cit_elasticity_filename'] = "elasticity_cit_egypt.json"
self.vars['cit_functions_filename'] = "functions_cit_egypt.py"
self.vars['cit_function_names_filename'] = "function_names_cit_egypt.json"
self.vars['gdp_filename'] = 'gdp_nominal_egypt.csv'
self.vars['gdp_filename'] = 'gdp_nominal_egypt.csv'
"""
self.vars['DEFAULTS_FILENAME'] = "current_law_policy_cit_training.json"
self.vars['GROWFACTORS_FILENAME'] = "growfactors_cit_training.csv"
Expand Down Expand Up @@ -258,7 +258,9 @@ def display_entry(self, widget, tax_type):
self.entry_functions_names_filename[tax_type].destroy()
self.button_function_names_filename[tax_type].destroy()
self.entry_benchmark_filename[tax_type].destroy()
self.button_benchmark_filename[tax_type].destroy()
self.button_benchmark_filename[tax_type].destroy()
self.entry_gdp_filename[tax_type].destroy()
self.button_gdp_filename[tax_type].destroy()
self.l2[tax_type].destroy()
self.entry_salary_variable[tax_type].destroy()
self.l3[tax_type].destroy()
Expand All @@ -279,10 +281,10 @@ def display_entry(self, widget, tax_type):
#self.vars['GROWFACTORS_FILENAME'] = "growfactors_egypt.csv"
self.vars['DEFAULTS_FILENAME'] = "current_law_policy_cit_training.json"
self.vars['GROWFACTORS_FILENAME'] = "growfactors_cit_training.csv"
self.vars['start_year'] = 2020
self.vars['data_start_year'] = 2020
self.vars['start_year'] = 2022
self.vars['data_start_year'] = 2020
self.vars['SALARY_VARIABLE'] = "SALARY"
self.vars['cit_id_var'] = 'id_n'
self.vars['cit_id_var'] = 'Taxpayer_ID'

self.grid_placement(block_1_title_pos_x)
self.l1[tax_type]=Label(self.TAB1,text="Data Inputs "+ tax_type.upper(),
Expand Down Expand Up @@ -439,7 +441,7 @@ def tab1(self):
self.vars['vat'] = 0

self.status['pit'] = tk.NORMAL
self.status['cit'] = tk.DISABLED
self.status['cit'] = tk.NORMAL
#self.status['vat'] = tk.NORMAL
self.status['vat'] = tk.DISABLED

Expand Down
19 changes: 11 additions & 8 deletions gui_tab6.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ def formatter(x, pos):
#tax_type = selected_chart[:3]
if global_vars['pit']:
tax_type = 'pit'
tax_collection_var = 'pitax'
elif global_vars['cit']:
tax_type = 'cit'
tax_collection_var = 'citax'
else:
tax_type = 'pit'
tax_type = 'vat'
start_year= global_vars['start_year']
data_start_year= global_vars['data_start_year']
kakwani_list = global_vars['kakwani_list']
kakwani_list = global_vars['kakwani_list']

if (selected_chart==tax_type+'_revenue_projection'):
df = pd.read_csv(selected_chart+'.csv', index_col=0)
df = df.T
Expand Down Expand Up @@ -143,8 +146,8 @@ def formatter(x, pos):
df.index.names = ['Decile']
fig, ax = plt.subplots(figsize=(8, 8))
#drop the rows that includes the average and top 1%
df=df[:-4]
ax = df.plot(kind='bar',y=['pitax_'+str(data_start_year), 'pitax_'+str(start_year), 'pitax_ref_'+str(start_year)],figsize=(7, 7))
df=df[:-4]
ax = df.plot(kind='bar',y=[tax_collection_var+'_'+str(data_start_year), tax_collection_var+'_'+str(start_year), tax_collection_var+'_ref_'+str(start_year)],figsize=(7, 7))
ax.set_xlabel("Assessable Income Deciles")
ax.yaxis.set_major_formatter(formatter)
ax.yaxis.set_minor_formatter(NullFormatter())
Expand All @@ -162,7 +165,7 @@ def formatter(x, pos):
df = df.set_index('index')
df.index.names = ['Decile']
fig, ax = plt.subplots(figsize=(8, 8))
ax=df.plot(kind='bar',y=['pitax_'+str(data_start_year), 'pitax_'+str(start_year), 'pitax_ref_'+str(start_year)],figsize=(7, 7))
ax=df.plot(kind='bar',y=[tax_collection_var+'_'+str(data_start_year), tax_collection_var+'_'+str(start_year), tax_collection_var+'_ref_'+str(start_year)],figsize=(7, 7))
ax.set_xlabel("Assessable Income Deciles")
ax.yaxis.set_major_formatter(formatter)
ax.yaxis.set_minor_formatter(NullFormatter())
Expand All @@ -180,10 +183,10 @@ def formatter(x, pos):
df = df.set_index('index')
df.index.names = ['Income Group']
#df1=df[df.columns[0]][2:][:-1]
df1 = df[['pitax_'+str(start_year),'pitax_ref_'+str(start_year)]][2:][:-1]
df1 = df[[tax_collection_var+'_'+str(start_year), tax_collection_var+'_ref_'+str(start_year)]][2:][:-1]
#print('df1 is ', df1)
df1['pct1'] = df1['pitax_'+str(start_year)]/df1['pitax_'+str(start_year)].sum()
df1['pct2'] = df1['pitax_ref_'+str(start_year)]/df1['pitax_ref_'+str(start_year)].sum()
df1['pct1'] = df1[tax_collection_var+'_'+str(start_year)]/df1[tax_collection_var+'_'+str(start_year)].sum()
df1['pct2'] = df1[tax_collection_var+'_ref_'+str(start_year)]/df1[tax_collection_var+'_ref_'+str(start_year)].sum()
labels1 = []
for i in range(len(df1['pct1'])):
if df1['pct1'][i]<0.05:
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def dataframe_cit(self, variable_list, attribute_value=None, attribute_var=None)
del arys
return pdf

def dataframe_gst(self, variable_list):
def dataframe_vat(self, variable_list):
"""
Return pandas DataFrame containing the listed variables from embedded
Records object.
Expand Down
Loading

0 comments on commit b8b21fa

Please sign in to comment.