From 8a1820dfcf50574fe6d2584937435793d403467c Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 8 May 2020 13:23:08 -0400 Subject: [PATCH 01/11] add labels for other series --- ogusa/constants.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ogusa/constants.py b/ogusa/constants.py index 8f4c9c0ab..879706315 100644 --- a/ogusa/constants.py +++ b/ogusa/constants.py @@ -33,6 +33,8 @@ 'w': 'Wage rate', 'BQ': 'Aggregate bequests ($BQ_{j,t}$)', 'total_revenue': 'Total tax revenue ($REV_t$)', 'business_revenue': 'Business tax revenue', + 'iit_revenue': 'Individual income tax revenue', + 'payroll_tax_revenue': 'Payroll tax revenue', 'IITpayroll_revenue': 'IIT and payroll tax revenue', 'n_mat': 'Labor Supply ($n_{j,s,t}$)', 'c_path': 'Consumption ($c_{j,s,t}$)', From 6b05c334ef0eafa35448b8b0024e09af9dd75fdd Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 8 May 2020 13:27:21 -0400 Subject: [PATCH 02/11] change default start year --- ogusa/output_tables.py | 4 ++-- ogusa/parameter_plots.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ogusa/output_tables.py b/ogusa/output_tables.py index 0e7a8c9be..328132ca9 100644 --- a/ogusa/output_tables.py +++ b/ogusa/output_tables.py @@ -1,7 +1,7 @@ import numpy as np import pandas as pd import os -from ogusa.constants import VAR_LABELS +from ogusa.constants import VAR_LABELS, DEFAULT_START_YEAR from ogusa import wealth from ogusa.utils import save_return_table, Inequality cur_path = os.path.split(os.path.abspath(__file__))[0] @@ -11,7 +11,7 @@ def macro_table(base_tpi, base_params, reform_tpi=None, reform_params=None, var_list=['Y', 'C', 'K', 'L', 'r', 'w'], output_type='pct_diff', num_years=10, include_SS=True, - include_overall=True, start_year=2019, + include_overall=True, start_year=DEFAULT_START_YEAR, table_format=None, path=None): ''' Create a table of macro aggregates. diff --git a/ogusa/parameter_plots.py b/ogusa/parameter_plots.py index a85237bde..074384cdb 100644 --- a/ogusa/parameter_plots.py +++ b/ogusa/parameter_plots.py @@ -4,12 +4,14 @@ import matplotlib from ogusa.constants import GROUP_LABELS from ogusa import utils +from ogusa.constants import DEFAULT_START_YEAR CUR_PATH = os.path.split(os.path.abspath(__file__))[0] style_file = os.path.join(CUR_PATH, 'OGUSAplots.mplstyle') plt.style.use(style_file) -def plot_imm_rates(p, year=2019, include_title=False, path=None): +def plot_imm_rates(p, year=DEFAULT_START_YEAR, include_title=False, + path=None): ''' Create a plot of immigration rates from OG-USA parameterization. @@ -71,8 +73,9 @@ def plot_mort_rates(p, include_title=False, path=None): plt.savefig(fig_path) -def plot_pop_growth(p, start_year=2019, num_years_to_plot=150, - include_title=False, path=None): +def plot_pop_growth(p, start_year=DEFAULT_START_YEAR, + num_years_to_plot=150, include_title=False, + path=None): ''' Create a plot of population growth rates by year. From 9484efa8c27e31a41b9f9ed3fbee9b1bd0d745bb Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 8 May 2020 14:05:52 -0400 Subject: [PATCH 03/11] make variale names appear in tables --- ogusa/output_tables.py | 2 ++ ogusa/parameter_tables.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ogusa/output_tables.py b/ogusa/output_tables.py index 328132ca9..a0165fe3b 100644 --- a/ogusa/output_tables.py +++ b/ogusa/output_tables.py @@ -130,6 +130,8 @@ def macro_table(base_tpi, base_params, reform_tpi=None, # Make df with dict so can use pandas functions table_df = pd.DataFrame.from_dict(table_dict, orient='columns' ).set_index('Year').transpose() + table_df.reset_index(inplace=True) + table_df.rename(columns={'index': 'Variable'}, inplace=True) table = save_return_table(table_df, table_format, path) return table diff --git a/ogusa/parameter_tables.py b/ogusa/parameter_tables.py index a0f902be0..f00cc6d74 100644 --- a/ogusa/parameter_tables.py +++ b/ogusa/parameter_tables.py @@ -118,7 +118,7 @@ def tax_rate_table(base_TxFuncEst, base_params, reform_TxFuncEst=None, len_rates = len(base_rates[start_index: start_index + num_years]) table = { - 'Year': years[:len_rates], + 'Year': years[:len_rates], 'Baseline ' + VAR_LABELS[rate_type]: base_rates[start_index: start_index + num_years], 'Reform ' + VAR_LABELS[rate_type]: @@ -130,6 +130,8 @@ def tax_rate_table(base_TxFuncEst, base_params, reform_TxFuncEst=None, 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_df.reset_index(inplace=True) + table_df.rename(columns={'index': 'Variable'}, inplace=True) table_str = save_return_table(table_df, table_format, path, precision=2) From c82a1f2cebfcea8520ea3a694120289c994d1f5f Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 8 May 2020 14:18:24 -0400 Subject: [PATCH 04/11] improve line length --- ogusa/fiscal.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ogusa/fiscal.py b/ogusa/fiscal.py index c605ed901..57f9d66d9 100644 --- a/ogusa/fiscal.py +++ b/ogusa/fiscal.py @@ -86,12 +86,14 @@ def D_G_path(r_gov, dg_fixed_values, p): G[t - 1] + TR[t - 1] - total_revenue[t - 1])) if (t >= p.tG1) and (t < p.tG2): - G[t] = (growth[t + 1] * (p.rho_G * p.debt_ratio_ss * Y[t] + - (1 - p.rho_G) * D[t]) - - (1 + r_gov[t]) * D[t] + total_revenue[t] - TR[t]) + G[t] = ( + growth[t + 1] * (p.rho_G * p.debt_ratio_ss * Y[t] + + (1 - p.rho_G) * D[t]) - + (1 + r_gov[t]) * D[t] + total_revenue[t] - TR[t]) elif t >= p.tG2: - G[t] = (growth[t + 1] * (p.debt_ratio_ss * Y[t]) - - (1 + r_gov[t]) * D[t] + total_revenue[t] - TR[t]) + G[t] = ( + growth[t + 1] * (p.debt_ratio_ss * Y[t]) - + (1 + r_gov[t]) * D[t] + total_revenue[t] - TR[t]) t += 1 # in final period, growth rate has stabilized, so we can replace From ce7e0af51a50c315e63a6947dc04232f87434c1e Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 8 May 2020 14:30:33 -0400 Subject: [PATCH 05/11] fixed with ability bar plot --- ogusa/output_plots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ogusa/output_plots.py b/ogusa/output_plots.py index 29dc862ff..3e8b2115c 100644 --- a/ogusa/output_plots.py +++ b/ogusa/output_plots.py @@ -335,7 +335,6 @@ def ability_bar(base_tpi, base_params, reform_tpi, plt.ylabel(r'Percentage Change in ' + VAR_LABELS[var]) if plot_title: plt.title(plot_title, fontsize=15) - plt.legend(loc=9, bbox_to_anchor=(0.5, -0.15), ncol=2) if path: fig_path1 = os.path.join(path) plt.savefig(fig_path1, bbox_inches="tight") @@ -664,7 +663,8 @@ def plot_all(base_output_path, reform_output_path, save_path): path_list = ['Cons', 'Labor', 'Save', 'ETR', 'MTRx', 'MTRy'] for i, v in enumerate(var_list): ability_bar(base_tpi, base_params, reform_tpi, reform_params, - var=v, num_years=10, start_year=DEFAULT_START_YEAR, + var=v, num_years=10, + start_year=base_params.start_year, plot_title='Percentage changes in ' + title_list[i], path=os.path.join(save_path, 'PctChange_' + path_list[i] + '.png')) From 70f9aee3bcb9b477577469964a2e9a2dc7a4ad89 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Sat, 9 May 2020 12:40:09 -0400 Subject: [PATCH 06/11] add income to list of plots --- ogusa/output_plots.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ogusa/output_plots.py b/ogusa/output_plots.py index 3e8b2115c..b2f94cb4f 100644 --- a/ogusa/output_plots.py +++ b/ogusa/output_plots.py @@ -655,12 +655,14 @@ def plot_all(base_output_path, reform_output_path, save_path): # Pct change in c, n, b, y, etr, mtrx, mtry by ability group over 10 years var_list = ['c_path', 'n_mat', 'bmat_splus1', 'etr_path', - 'mtrx_path', 'mtry_path'] + 'mtrx_path', 'mtry_path', 'y_before_tax_mat'] title_list = ['consumption', 'labor supply', 'savings', 'effective tax rates', 'marginal tax rates on labor income', - 'marginal tax rates on capital income'] - path_list = ['Cons', 'Labor', 'Save', 'ETR', 'MTRx', 'MTRy'] + 'marginal tax rates on capital income', + 'before tax income'] + path_list = ['Cons', 'Labor', 'Save', 'ETR', 'MTRx', 'MTRy', + 'Income'] for i, v in enumerate(var_list): ability_bar(base_tpi, base_params, reform_tpi, reform_params, var=v, num_years=10, From d28c20c61b0f5b28a2c4c0e41ea4a21faf4f3e2c Mon Sep 17 00:00:00 2001 From: jdebacker Date: Tue, 12 May 2020 09:46:08 -0400 Subject: [PATCH 07/11] version bump --- cs-config/cs_config/functions.py | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cs-config/cs_config/functions.py b/cs-config/cs_config/functions.py index bf72a837c..5e91c930d 100644 --- a/cs-config/cs_config/functions.py +++ b/cs-config/cs_config/functions.py @@ -65,7 +65,7 @@ class MetaParams(paramtools.Parameters): def get_version(): - return "0.6.0" + return "0.6.2" def get_inputs(meta_param_dict): diff --git a/setup.py b/setup.py index 5a466b8c7..ce45b86be 100755 --- a/setup.py +++ b/setup.py @@ -4,9 +4,9 @@ from distutils.core import setup with open('README.md') as f: - longdesc = f.read() + longdesc = f.read() -version = '0.5.13' +version = '0.6.2' config = { 'description': 'General equilibribum, overlapping generations model for the USA', From 0f1bc4242791ffba9be876ae9d1941aa31ed3420 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Tue, 12 May 2020 10:22:44 -0400 Subject: [PATCH 08/11] move one test out of Travis CI runs to reduce run time --- ogusa/tests/test_TPI.py | 60 +++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/ogusa/tests/test_TPI.py b/ogusa/tests/test_TPI.py index 96f093add..51d1bf67c 100644 --- a/ogusa/tests/test_TPI.py +++ b/ogusa/tests/test_TPI.py @@ -285,10 +285,6 @@ def test_run_TPI_full_run(baseline, param_updates, filename, tmp_path, param_updates5 = {'zeta_K': [1.0]} filename5 = os.path.join(CUR_PATH, 'test_io_data', 'run_TPI_outputs_baseline_small_open_2.pkl') -param_updates6 = {'zeta_K': [0.2, 0.2, 0.2, 1.0, 1.0, 1.0, 0.2]} -filename6 = os.path.join( - CUR_PATH, 'test_io_data', - 'run_TPI_outputs_baseline_small_open_some_periods_2.pkl') @pytest.mark.parametrize('baseline,param_updates,filename', @@ -296,12 +292,10 @@ def test_run_TPI_full_run(baseline, param_updates, filename, tmp_path, (True, param_updates1, filename1), (False, param_updates3, filename3), (False, param_updates4, filename4), - (True, param_updates5, filename5), - (True, param_updates6, filename6)], + (True, param_updates5, filename5)], ids=['Baseline, balanced budget', 'Baseline', 'Reform', 'Reform, baseline spending', - 'Baseline, small open', - 'Baseline, small open some periods']) + 'Baseline, small open']) def test_run_TPI(baseline, param_updates, filename, tmp_path, dask_client): ''' @@ -349,3 +343,53 @@ def test_run_TPI(baseline, param_updates, filename, tmp_path, except ValueError: assert(np.allclose(test_dict[k], v[:p.T, :, :], rtol=1e-04, atol=1e-04)) + + +@pytest.mark.full_run +def test_run_TPI_small_open_some_periods(tmp_path, dask_client): + ''' + Test TPI.run_TPI function. Provide inputs to function and + ensure that output returned matches what it has been before. + ''' + filename = os.path.join( + CUR_PATH, 'test_io_data', + 'run_TPI_outputs_baseline_small_open_some_periods_2.pkl') + baseline_dir = os.path.join(CUR_PATH, 'baseline') + output_base = baseline_dir + p = Specifications(baseline=True, baseline_dir=baseline_dir, + output_base=output_base, test=True, + client=dask_client, num_workers=NUM_WORKERS) + param_updates = {'zeta_K': [0.2, 0.2, 0.2, 1.0, 1.0, 1.0, 0.2]} + p.update_specifications(param_updates) + p.maxiter = 2 # this test runs through just two iterations + p.get_tax_function_parameters( + None, run_micro=False, + tax_func_path=os.path.join( + CUR_PATH, '..', 'data', 'tax_functions', + 'TxFuncEst_baseline_CPS.pkl')) + + # Need to run SS first to get results + SS.ENFORCE_SOLUTION_CHECKS = False + ss_outputs = SS.run_SS(p, None) + + if p.baseline: + utils.mkdirs(os.path.join(p.baseline_dir, "SS")) + ss_dir = os.path.join(p.baseline_dir, "SS", "SS_vars.pkl") + with open(ss_dir, "wb") as f: + pickle.dump(ss_outputs, f) + else: + utils.mkdirs(os.path.join(p.output_base, "SS")) + ss_dir = os.path.join(p.output_base, "SS", "SS_vars.pkl") + with open(ss_dir, "wb") as f: + pickle.dump(ss_outputs, f) + + TPI.ENFORCE_SOLUTION_CHECKS = False + test_dict = TPI.run_TPI(p, None) + expected_dict = utils.safe_read_pickle(filename) + + for k, v in expected_dict.items(): + try: + assert(np.allclose(test_dict[k], v, rtol=1e-04, atol=1e-04)) + except ValueError: + assert(np.allclose(test_dict[k], v[:p.T, :, :], rtol=1e-04, + atol=1e-04)) From 62751d31e2151765c053ac669edd400b2c0daa1a Mon Sep 17 00:00:00 2001 From: jdebacker Date: Tue, 12 May 2020 13:04:57 -0400 Subject: [PATCH 09/11] build and test just for python 3.7 --- .travis.yml | 1 - setup.py | 1 - 2 files changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd165bbe9..1c16656c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ sudo: false dist: xenial language: python python: - - "3.6" - "3.7" install: diff --git a/setup.py b/setup.py index ce45b86be..1303d114e 100755 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Topic :: Software Development :: Libraries :: Python Modules'], 'tests_require': ['pytest'] From 46eeacbf153fab7f9b43976a2eed88ef9a985f8f Mon Sep 17 00:00:00 2001 From: jdebacker Date: Tue, 12 May 2020 16:07:44 -0400 Subject: [PATCH 10/11] add pyton 3.8 --- .travis.yml | 1 + setup.py | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1c16656c2..ddc2672ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ dist: xenial language: python python: - "3.7" + - "3.8" install: # Install conda diff --git a/setup.py b/setup.py index 1303d114e..157b97419 100755 --- a/setup.py +++ b/setup.py @@ -37,6 +37,7 @@ 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: Software Development :: Libraries :: Python Modules'], 'tests_require': ['pytest'] } From 067b71caeeebc582861b32c4e66eaacd35fbbc05 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Tue, 12 May 2020 16:08:06 -0400 Subject: [PATCH 11/11] take one more function out of travis CI tests to reduce run time --- ogusa/tests/test_TPI.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ogusa/tests/test_TPI.py b/ogusa/tests/test_TPI.py index 51d1bf67c..26884d002 100644 --- a/ogusa/tests/test_TPI.py +++ b/ogusa/tests/test_TPI.py @@ -282,20 +282,15 @@ def test_run_TPI_full_run(baseline, param_updates, filename, tmp_path, param_updates4 = {'baseline_spending': True} filename4 = os.path.join(CUR_PATH, 'test_io_data', 'run_TPI_outputs_reform_baseline_spend_2.pkl') -param_updates5 = {'zeta_K': [1.0]} -filename5 = os.path.join(CUR_PATH, 'test_io_data', - 'run_TPI_outputs_baseline_small_open_2.pkl') @pytest.mark.parametrize('baseline,param_updates,filename', [(True, param_updates2, filename2), (True, param_updates1, filename1), (False, param_updates3, filename3), - (False, param_updates4, filename4), - (True, param_updates5, filename5)], + (False, param_updates4, filename4)], ids=['Baseline, balanced budget', 'Baseline', - 'Reform', 'Reform, baseline spending', - 'Baseline, small open']) + 'Reform', 'Reform, baseline spending']) def test_run_TPI(baseline, param_updates, filename, tmp_path, dask_client): ''' @@ -345,21 +340,32 @@ def test_run_TPI(baseline, param_updates, filename, tmp_path, atol=1e-04)) +param_updates5 = {'zeta_K': [1.0]} +filename5 = os.path.join(CUR_PATH, 'test_io_data', + 'run_TPI_outputs_baseline_small_open_2.pkl') +param_updates6 = {'zeta_K': [0.2, 0.2, 0.2, 1.0, 1.0, 1.0, 0.2]} +filename6 = filename = os.path.join( + CUR_PATH, 'test_io_data', + 'run_TPI_outputs_baseline_small_open_some_periods_2.pkl') + + @pytest.mark.full_run -def test_run_TPI_small_open_some_periods(tmp_path, dask_client): +@pytest.mark.parametrize('baseline,param_updates,filename', + [(True, param_updates5, filename5), + (True, param_updates6, filename6)], + ids=['Baseline, small open', + 'Baseline, small open for some periods']) +def test_run_TPI_extra(baseline, param_updates, filename, tmp_path, + dask_client): ''' Test TPI.run_TPI function. Provide inputs to function and ensure that output returned matches what it has been before. ''' - filename = os.path.join( - CUR_PATH, 'test_io_data', - 'run_TPI_outputs_baseline_small_open_some_periods_2.pkl') baseline_dir = os.path.join(CUR_PATH, 'baseline') output_base = baseline_dir p = Specifications(baseline=True, baseline_dir=baseline_dir, output_base=output_base, test=True, client=dask_client, num_workers=NUM_WORKERS) - param_updates = {'zeta_K': [0.2, 0.2, 0.2, 1.0, 1.0, 1.0, 0.2]} p.update_specifications(param_updates) p.maxiter = 2 # this test runs through just two iterations p.get_tax_function_parameters(