Skip to content

Commit

Permalink
Merge pull request #547 from jdebacker/new_year
Browse files Browse the repository at this point in the history
Looks good, Merging.
  • Loading branch information
rickecon authored Apr 17, 2020
2 parents 5eded50 + 6ef40b4 commit f0229fe
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 19 deletions.
12 changes: 9 additions & 3 deletions cs-config/cs_config/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ def comp_output(base_params, base_ss, reform_params, reform_ss,
base_tpi, base_params, reform_tpi, reform_params,
var_list=['Y', 'C', 'K', 'L'], plot_type='pct_diff',
num_years_to_plot=50, start_year=base_params.start_year,
vertical_line_years=[base_params.tG1, base_params.tG2],
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
plot_title=None, path=None)
in_memory_file1 = io.BytesIO()
fig1.savefig(in_memory_file1, format="png", bbox_inches="tight")
Expand All @@ -281,7 +283,9 @@ def comp_output(base_params, base_ss, reform_params, reform_ss,
base_tpi, base_params, reform_tpi, reform_params,
var_list=['r_gov', 'w'], plot_type='pct_diff',
num_years_to_plot=50, start_year=base_params.start_year,
vertical_line_years=[base_params.tG1, base_params.tG2],
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
plot_title=None, path=None)
in_memory_file2 = io.BytesIO()
fig2.savefig(in_memory_file2, format="png", bbox_inches="tight")
Expand All @@ -291,7 +295,9 @@ def comp_output(base_params, base_ss, reform_params, reform_ss,
var_list=['D', 'G', 'total_revenue'],
plot_type='diff', num_years_to_plot=50,
start_year=base_params.start_year,
vertical_line_years=[base_params.tG1, base_params.tG2],
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
plot_title=None, path=None)
in_memory_file3 = io.BytesIO()
fig3.savefig(in_memory_file3, format="png", bbox_inches="tight")
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- matplotlib
- "taxcalc>=2.4.2"
- "dask>=0.20.0"
- "paramtools>=0.7.1"
- "paramtools>=0.13.0"
- openpyxl
- pip
- pytest
Expand Down
2 changes: 1 addition & 1 deletion ogusa/TPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def run_TPI(p, client=None):
else:
K_init = B_init * ss_vars['Kss'] / ss_vars['Bss']
else:
K_init = firm.get_B(L_init, p.firm_r, p, 'TPI')
K_init = firm.get_K(L_init, p.firm_r, p, 'TPI')

K = K_init
K_d = K_init * ss_vars['K_d_ss'] / ss_vars['Kss']
Expand Down
Binary file modified ogusa/data/tax_functions/TxFuncEst_baseline_CPS.pkl
Binary file not shown.
Binary file modified ogusa/data/tax_functions/TxFuncEst_baseline_PUF.pkl
Binary file not shown.
1 change: 1 addition & 0 deletions ogusa/default_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@
"section_2": "Taxes",
"notes": "This policy parameter represents the effective consumption tax rate from sales taxes, VATs, and excise taxes. To capture exemptions of certain goods, this is assumed to vary by age and ability type. It is thus a SxJ matrix.",
"type": "float",
"number_dims": 1,
"value": [
{
"value": [
Expand Down
25 changes: 18 additions & 7 deletions ogusa/output_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def plot_aggregates(base_tpi, base_params, reform_tpi=None,
plt.title(plot_title, fontsize=15)
vals = ax1.get_yticks()
if plot_type == 'pct_diff':
ax1.set_yticklabels(['{:,.0%}'.format(x) for x in vals])
ax1.set_yticklabels(['{:,.2%}'.format(x) for x in vals])
plt.xlim((base_params.start_year - 1, base_params.start_year +
num_years_to_plot))
plt.legend(loc=9, bbox_to_anchor=(0.5, -0.15), ncol=2)
Expand Down Expand Up @@ -273,7 +273,10 @@ def plot_gdp_ratio(base_tpi, base_params, reform_tpi=None,
if plot_title:
plt.title(plot_title, fontsize=15)
vals = ax1.get_yticks()
ax1.set_yticklabels(['{:,.0%}'.format(x) for x in vals])
if plot_type == 'levels':
ax1.set_yticklabels(['{:,.0%}'.format(x) for x in vals])
else:
ax1.set_yticklabels(['{:,.2%}'.format(x) for x in vals])
plt.xlim((base_params.start_year - 1, base_params.start_year +
num_years_to_plot))
plt.legend(loc=9, bbox_to_anchor=(0.5, -0.15), ncol=2)
Expand Down Expand Up @@ -557,6 +560,8 @@ def plot_all(base_output_path, reform_output_path, save_path):
None: All output figures saved to disk.
'''
# Make directory in case it doesn't exist
utils.mkdirs(save_path)
# Read in data
# Read in TPI output and parameters
base_tpi = utils.safe_read_pickle(
Expand Down Expand Up @@ -587,6 +592,7 @@ def plot_all(base_output_path, reform_output_path, save_path):
reform_params=reform_params,
var_list=['Y', 'K', 'L', 'C'], plot_type='pct_diff',
num_years_to_plot=150,
start_year=base_params.start_year,
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
Expand All @@ -598,6 +604,7 @@ def plot_all(base_output_path, reform_output_path, save_path):
reform_params=reform_params,
var_list=['D', 'G', 'TR', 'total_revenue'],
plot_type='pct_diff', num_years_to_plot=150,
start_year=base_params.start_year,
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
Expand All @@ -609,6 +616,7 @@ def plot_all(base_output_path, reform_output_path, save_path):
reform_params=reform_params,
var_list=['r'],
plot_type='levels', num_years_to_plot=150,
start_year=base_params.start_year,
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
Expand All @@ -619,6 +627,7 @@ def plot_all(base_output_path, reform_output_path, save_path):
reform_params=reform_params,
var_list=['w'],
plot_type='levels', num_years_to_plot=150,
start_year=base_params.start_year,
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
Expand All @@ -628,7 +637,8 @@ def plot_all(base_output_path, reform_output_path, save_path):
# Debt-GDP in base and reform-- vertical lines at tG1, tG2
plot_gdp_ratio(base_tpi, base_params, reform_tpi, reform_params,
var_list=['D'], num_years_to_plot=150,
start_year=DEFAULT_START_YEAR, vertical_line_years=[
start_year=base_params.start_year,
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
plot_title='Debt-to-GDP',
Expand All @@ -637,7 +647,8 @@ def plot_all(base_output_path, reform_output_path, save_path):
# Tax revenue to GDP in base and reform-- vertical lines at tG1, tG2
plot_gdp_ratio(base_tpi, base_params, reform_tpi, reform_params,
var_list=['total_revenue'], num_years_to_plot=150,
start_year=DEFAULT_START_YEAR, vertical_line_years=[
start_year=base_params.start_year,
vertical_line_years=[
base_params.start_year + base_params.tG1,
base_params.start_year + base_params.tG2],
plot_title='Tax Revenue to GDP',
Expand Down Expand Up @@ -685,8 +696,8 @@ def plot_all(base_output_path, reform_output_path, save_path):
def inequality_plot(
base_tpi, base_params, reform_tpi=None, reform_params=None,
var='c_path', ineq_measure='gini', pctiles=None, plot_type='levels',
num_years_to_plot=50, start_year=DEFAULT_START_YEAR, vertical_line_years=None,
plot_title=None, path=None):
num_years_to_plot=50, start_year=DEFAULT_START_YEAR,
vertical_line_years=None, plot_title=None, path=None):
'''
Plot measures of inequality over the time path.
Expand Down Expand Up @@ -794,7 +805,7 @@ def inequality_plot(
plt.title(plot_title, fontsize=15)
vals = ax1.get_yticks()
if plot_type == 'pct_diff':
ax1.set_yticklabels(['{:,.0%}'.format(x) for x in vals])
ax1.set_yticklabels(['{:,.2%}'.format(x) for x in vals])
plt.xlim((base_params.start_year - 1, base_params.start_year +
num_years_to_plot))
plt.legend(loc=9, bbox_to_anchor=(0.5, -0.15), ncol=2)
Expand Down
2 changes: 1 addition & 1 deletion ogusa/output_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def macro_table_SS(base_ss, reform_ss,
table_dict['Baseline'].append(base_ss[v])
table_dict['Reform'].append(reform_ss[v])
if v != 'D/Y':
diff = (reform_ss[v] - base_ss[v]) / base_ss[v]
diff = ((reform_ss[v] - base_ss[v]) / base_ss[v]) * 100
else:
diff = (reform_ss['Dss'] / reform_ss['Yss'] -
base_ss['Dss'] / base_ss['Yss'])
Expand Down
15 changes: 9 additions & 6 deletions ogusa/parameter_tables.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pandas as pd
import numpy as np
from ogusa.utils import save_return_table
from ogusa.constants import VAR_LABELS, PARAM_LABELS
from ogusa.constants import VAR_LABELS, PARAM_LABELS, DEFAULT_START_YEAR


def tax_rate_table(base_TxFuncEst, base_params, reform_TxFuncEst=None,
reform_params=None, rate_type='ETR', start_year=2019,
num_years=10, table_format='tex', path=None):
reform_params=None, rate_type='ETR',
start_year=DEFAULT_START_YEAR, num_years=10,
table_format='tex', path=None):
'''
Table of average tax rates over several years.
Expand All @@ -29,8 +30,8 @@ def tax_rate_table(base_TxFuncEst, base_params, reform_TxFuncEst=None,
table_str (string or DataFrame): table of tax rates
'''
assert (isinstance(start_year, int))
assert (isinstance(num_years, int))
assert isinstance(start_year, (int, np.integer))
assert isinstance(num_years, (int, np.integer))
# Make sure both runs cover same time period
if reform_TxFuncEst is not None:
assert (base_params.start_year == reform_params.start_year)
Expand Down Expand Up @@ -116,7 +117,8 @@ def tax_rate_table(base_TxFuncEst, base_params, reform_TxFuncEst=None,
else:
len_rates = len(base_rates[start_index: start_index +
num_years])
table = {'Year': years[:len_rates],
table = {
'Year': years[:len_rates],
'Baseline ' + VAR_LABELS[rate_type]:
base_rates[start_index: start_index + num_years],
'Reform ' + VAR_LABELS[rate_type]:
Expand All @@ -127,6 +129,7 @@ def tax_rate_table(base_TxFuncEst, base_params, reform_TxFuncEst=None,
table_df = (pd.DataFrame.from_dict(table, orient='columns')).transpose()
table_df.columns = table_df.iloc[0].astype('int').astype('str')
table_df.reindex(table_df.index.drop('Year'))
table_df.drop('Year', inplace=True)
table_str = save_return_table(table_df, table_format, path,
precision=2)

Expand Down

0 comments on commit f0229fe

Please sign in to comment.