Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
06b2d9b
add all output_plot functions to api docs
jdebacker Mar 22, 2025
84b20fd
wrap line
jdebacker Mar 22, 2025
ef3f05f
wrap line in pp
jdebacker Mar 22, 2025
eedd9cb
change name of tp_dump_output_table to time_series_table
jdebacker Mar 22, 2025
82d7bc3
change default for stationarized option in plot_aggregats
jdebacker Mar 22, 2025
92db6e3
update stationary untility for new var names
jdebacker Mar 22, 2025
d5b3f5d
generalize stationarization function
jdebacker Mar 22, 2025
f45acf8
expand unstationarization of vars for plots
jdebacker Mar 22, 2025
fcafa18
test passing for new unstationarize func
jdebacker Mar 22, 2025
73971bc
allows stationarization option for time series table
jdebacker Mar 22, 2025
77b2226
use new stationarization func
jdebacker Mar 22, 2025
941a994
set dim for multi sector
jdebacker Mar 22, 2025
bebca5f
update api docs for changes in utils.py
jdebacker Mar 22, 2025
ca80d81
bump version and update changelog
jdebacker Mar 22, 2025
2deb848
Updated README.md
rickecon Mar 22, 2025
d5ca50d
change name of function that converts parameters to json file
jdebacker Mar 22, 2025
048eea6
format
jdebacker Mar 22, 2025
02d5196
proparly handle annual rates
jdebacker Mar 22, 2025
5f8aa7b
clean up changelog
jdebacker Mar 22, 2025
cee20bc
Update README.md
rickecon Apr 4, 2025
f769362
Updated README.md
rickecon Apr 4, 2025
c244c77
Updated README.md
rickecon Apr 4, 2025
843fc40
Updated README.md
rickecon Apr 4, 2025
bdce30f
Update ogcore/output_tables.py
rickecon Apr 4, 2025
4f74cbd
Update CHANGELOG.md
rickecon Apr 4, 2025
bf75ac7
Updated intro.md
rickecon Apr 4, 2025
e321ef9
Merge pull request #36 from rickecon/jdebacker-plot_tables
jdebacker Apr 4, 2025
3c67f9c
merge in Rick updates, change date
jdebacker Apr 4, 2025
70c107f
set stationarized to true as default for all plots/tables
jdebacker Apr 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.14.2] - 2025-04-04 12:00:00

### Added

- `utils.pct_change_unstationarized` replaced with `utils.unstationarize_vars`, which allows for more general use of a utility to find unstationarized values of time series output
- `output_plots.py` and `output_tables.py` are updated to all for plots and tables of unstationarized output for variables of any type, not just percentage changes.
- `ouput_tables.tp_output_dump_table` has been renamed `output_tables.time_series_table`
- `utils.param_dump_json` has been renamed `utils.params_to_json`
- API docs have been updated to include functions left out previously and for new function names

## [0.14.1] - 2025-03-16 12:00:00

### Bug Fix
Expand Down Expand Up @@ -363,6 +373,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Version [0.7.0] on August 30, 2021 was the first time that the OG-USA repository was detached from all of the core model logic, which was named OG-Core. Before this version, OG-USA was part of what is now the [`OG-Core`](https://github.com/PSLmodels/OG-Core) repository. In the next version of OG-USA, we adjusted the version numbering to begin with 0.1.0. This initial version of 0.7.0, was sequential from what OG-USA used to be when the OG-Core project was called OG-USA.
- Any earlier versions of OG-USA can be found in the [`OG-Core`](https://github.com/PSLmodels/OG-Core) repository [release history](https://github.com/PSLmodels/OG-Core/releases) from [v.0.6.4](https://github.com/PSLmodels/OG-Core/releases/tag/v0.6.4) (Jul. 20, 2021) or earlier.

[0.14.2]: https://github.com/PSLmodels/OG-Core/compare/v0.14.1...v0.14.2
[0.14.1]: https://github.com/PSLmodels/OG-Core/compare/v0.14.0...v0.14.1
[0.14.0]: https://github.com/PSLmodels/OG-Core/compare/v0.13.2...v0.14.0
[0.13.2]: https://github.com/PSLmodels/OG-Core/compare/v0.13.1...v0.13.2
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
| | |
| --- | --- |
| Org | [![PSL cataloged](https://img.shields.io/badge/PSL-cataloged-a0a0a0.svg)](https://www.PSLmodels.org) [![OS License: CCO-1.0](https://img.shields.io/badge/OS%20License-CCO%201.0-yellow)](https://github.com/PSLmodels/OG-Core/blob/master/LICENSE) [![Jupyter Book Badge](https://jupyterbook.org/badge.svg)](https://pslmodels.github.io/OG-Core/) |
| Package | [![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-3916/) [![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3108/) [![Python 3.11](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3118/) [![PyPI Latest Release](https://img.shields.io/pypi/v/ogcore.svg)](https://pypi.org/project/ogcore/) [![PyPI Downloads](https://img.shields.io/pypi/dm/ogcore.svg?label=PyPI%20downloads)](https://pypi.org/project/ogcore/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) |
| Package | [![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-31111/) [![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3129/) [![PyPI Latest Release](https://img.shields.io/pypi/v/ogcore.svg)](https://pypi.org/project/ogcore/) [![PyPI Downloads](https://img.shields.io/pypi/dm/ogcore.svg?label=PyPI%20downloads)](https://pypi.org/project/ogcore/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) |
| Testing | ![example event parameter](https://github.com/PSLmodels/OG-Core/actions/workflows/build_and_test.yml/badge.svg?branch=master) ![example event parameter](https://github.com/PSLmodels/OG-Core/actions/workflows/deploy_docs.yml/badge.svg?branch=master) ![example event parameter](https://github.com/PSLmodels/OG-Core/actions/workflows/check_black.yml/badge.svg?branch=master) [![Codecov](https://codecov.io/gh/PSLmodels/OG-Core/branch/master/graph/badge.svg)](https://codecov.io/gh/PSLmodels/OG-Core) |


OG-Core is an overlapping-generations (OG) model core theory, logic, and solution method algorithms that allow for dynamic general equilibrium analysis of fiscal policy. OG-Core provides a general framework and is a dependency of several country-specific OG models, such as [OG-USA](https://github.com/PSLmodels/OG-USA) and [OG-UK](https://github.com/PSLmodels/OG-UK). The model output includes changes in macroeconomic aggregates (GDP, investment, consumption), wages, interest rates, and the stream of tax revenues over time. Regularly updated documentation of the model theory--its output, and solution method--and the Python API is available [here](https://pslmodels.github.io/OG-Core).
OG-Core is an overlapping-generations (OG) model core theory, logic, and solution method algorithms that allow for dynamic general equilibrium analysis of fiscal policy. OG-Core provides a general framework and is a dependency of several country-specific OG model caliibrations, as listed in the table belowsuch as [OG-USA](https://github.com/PSLmodels/OG-USA) and [OG-UK](https://github.com/PSLmodels/OG-UK). The model output includes changes in macroeconomic aggregates (GDP, investment, consumption), wages, interest rates, and the stream of tax revenues over time. Regularly updated documentation of the model theory--its output, and solution method--and the Python API is available [here](https://pslmodels.github.io/OG-Core).

**Country calibrations of OG-Core**
| | | |
| :-----------: | :---------: | :---------: |
| United States, [OG-USA](https://github.com/PSLmodels/OG-USA) | United Kingdom, [OG-UK](https://github.com/PSLmodels/OG-USA) | |
| Phillipines, [OG-PHL](https://github.com/EAPD-DRB/OG-PHL) | South Africa, [OG-ZAF](https://github.com/EAPD-DRB/OG-ZAF) | Indonesia, [OG-IDN](https://github.com/EAPD-DRB/OG-IDN) |
| India, [OG-IND](https://github.com/OpenSourceEcon/OG-IND) | Malaysia, [OG-MYS](https://github.com/OpenSourceEcon/OG-MYS) | |


## Disclaimer
Expand Down
5 changes: 3 additions & 2 deletions docs/book/content/api/output_plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ ogcore.output_plots
------------------------------------------

.. automodule:: ogcore.output_plots
:members: plot_aggregates, plot_gdp_ratio, ability_bar, ability_bar_ss,
ss_profiles, tpi_profiles, plot_all
:members: plot_aggregates, plot_industry_aggregates, ss_3Dplot,
plot_gdp_ratio, ability_bar, ability_bar_ss,
tpi_profiles, ss_profiles, plot_all, inequality_plot, lambda_labels
3 changes: 2 additions & 1 deletion docs/book/content/api/output_tables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ ogcore.output_tables

.. automodule:: ogcore.output_tables
:members: macro_table, macro_table_SS, ineq_table, gini_table,
wealth_moments_table, tp_output_dump_table, dynamic_revenue_decomposition
wealth_moments_table, time_series_table,
dynamic_revenue_decomposition
9 changes: 5 additions & 4 deletions docs/book/content/api/parameter_plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ ogcore.parameter_plots

.. automodule:: ogcore.parameter_plots
:members: plot_imm_rates, plot_mort_rates, plot_pop_growth,
plot_ability_profiles, plot_elliptical_u, plot_chi_n,
plot_fert_rates, plot_mort_rates_data, plot_g_n, plot_omega_fixed,
plot_imm_fixed, plot_population_path, gen_3Dscatters_hist,
txfunc_graph, txfunc_sse_plot, plot_income_data, plot_2D_taxfunc
plot_population, plot_ability_profiles, plot_elliptical_u,
plot_chi_n, plot_fert_rates, plot_mort_rates_data, plot_g_n,
plot_omega_fixed, plot_imm_fixed, plot_population_path,
gen_3Dscatters_hist, txfunc_graph, txfunc_sse_plot,
plot_income_data, plot_2D_taxfunc

2 changes: 1 addition & 1 deletion docs/book/content/api/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ ogcore.utils
to_timepath_shape, get_initial_path, safe_read_pickle, rate_conversion,
save_return_table, print_progress, fetch_files_from_web, not_connected,
avg_by_bin, extrapolate_arrays, get_legacy_session, shift_bio_clock,
pct_change_unstationarized, param_dump_json
unstationarize_vars, params_to_json
9 changes: 8 additions & 1 deletion docs/book/content/intro/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
| | |
| --- | --- |
| Org | [![PSL cataloged](https://img.shields.io/badge/PSL-cataloged-a0a0a0.svg)](https://www.PSLmodels.org) [![OS License: CCO-1.0](https://img.shields.io/badge/OS%20License-CCO%201.0-yellow)](https://github.com/PSLmodels/OG-Core/blob/master/LICENSE) [![Jupyter Book Badge](https://jupyterbook.org/badge.svg)](https://pslmodels.github.io/OG-Core/) |
| Package | [![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-3916/) [![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3108/) [![Python 3.11](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3118/) [![PyPI Latest Release](https://img.shields.io/pypi/v/ogcore.svg)](https://pypi.org/project/ogcore/) [![PyPI Downloads](https://img.shields.io/pypi/dm/ogcore.svg?label=PyPI%20downloads)](https://pypi.org/project/ogcore/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) |
| Package | [![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-31111/) [![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3129/) [![PyPI Latest Release](https://img.shields.io/pypi/v/ogcore.svg)](https://pypi.org/project/ogcore/) [![PyPI Downloads](https://img.shields.io/pypi/dm/ogcore.svg?label=PyPI%20downloads)](https://pypi.org/project/ogcore/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) |
| Testing | ![example event parameter](https://github.com/PSLmodels/OG-Core/actions/workflows/build_and_test.yml/badge.svg?branch=master) ![example event parameter](https://github.com/PSLmodels/OG-Core/actions/workflows/deploy_docs.yml/badge.svg?branch=master) ![example event parameter](https://github.com/PSLmodels/OG-Core/actions/workflows/check_black.yml/badge.svg?branch=master) [![Codecov](https://codecov.io/gh/PSLmodels/OG-Core/branch/master/graph/badge.svg)](https://codecov.io/gh/PSLmodels/OG-Core) |

`OG-Core` is the core logic for a country-agnostic overlapping-generations (OG) model of an economy that allows for dynamic general equilibrium analysis of fiscal policy. The source code is openly available for download or collaboration at the GitHub repository [www.github.com/PSLmodels/OG-Core](https://github.com/PSLmodels/OG-Core), or you can click on the GitHub icon at the top right of this page.

**Country calibrations of OG-Core**
| | | |
| :-----------: | :---------: | :---------: |
| United States, [OG-USA](https://github.com/PSLmodels/OG-USA) | United Kingdom, [OG-UK](https://github.com/PSLmodels/OG-USA) | |
| Phillipines, [OG-PHL](https://github.com/EAPD-DRB/OG-PHL) | South Africa, [OG-ZAF](https://github.com/EAPD-DRB/OG-ZAF) | Indonesia, [OG-IDN](https://github.com/EAPD-DRB/OG-IDN) |
| India, [OG-IND](https://github.com/OpenSourceEcon/OG-IND) | Malaysia, [OG-MYS](https://github.com/OpenSourceEcon/OG-MYS) | |

The model output focuses changes in macroeconomic aggregates (GDP, investment, consumption), wages, interest rates, and the stream of tax revenues over time. Although `OG-Core` can be run independently based on default parameter values (currently representing something similar to the United States), it is meant to be a dependency of a country-specific calibration. This documentation contains the following major sections, which are regularly updated.

* Contributing to `OG-Core`
Expand Down
2 changes: 1 addition & 1 deletion ogcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
from ogcore.txfunc import *
from ogcore.utils import *

__version__ = "0.14.1"
__version__ = "0.14.2"
33 changes: 20 additions & 13 deletions ogcore/output_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def plot_aggregates(
'levels': plot variables in model units
'forecast': plots variables in levels relative to baseline
economic forecast
stationarized (bool): whether used stationarized variables (False
only affects pct_diff right now)
stationarized (bool): whether used stationarized variables
num_years_to_plot (integer): number of years to include in plot
start_year (integer): year to start plot
forecast_data (array_like): baseline economic forecast series,
Expand All @@ -76,6 +75,13 @@ def plot_aggregates(
if plot_type == "pct_diff" or plot_type == "diff":
assert reform_tpi is not None
fig1, ax1 = plt.subplots()
if not stationarized:
for v in var_list:
base_tpi[v] = utils.unstationarize_vars(v, base_tpi, base_params)
if reform_tpi:
reform_tpi[v] = utils.unstationarize_vars(
v, reform_tpi, reform_params
)
for i, v in enumerate(var_list):
assert (
v in VAR_LABELS.keys()
Expand All @@ -85,17 +91,7 @@ def plot_aggregates(
# Compute just percentage point changes for rates
plot_var = reform_tpi[v] - base_tpi[v]
else:
if stationarized:
plot_var = (reform_tpi[v] - base_tpi[v]) / base_tpi[v]
else:
pct_changes = utils.pct_change_unstationarized(
base_tpi,
base_params,
reform_tpi,
reform_params,
output_vars=[v],
)
plot_var = pct_changes[v]
plot_var = (reform_tpi[v] - base_tpi[v]) / base_tpi[v]
ylabel = r"Pct. change"
plt.plot(
year_vec,
Expand Down Expand Up @@ -182,6 +178,7 @@ def plot_industry_aggregates(
var_list=["Y_m"],
ind_names_list=None,
plot_type="pct_diff",
stationarized=True,
num_years_to_plot=50,
start_year=DEFAULT_START_YEAR,
forecast_data=None,
Expand All @@ -201,6 +198,7 @@ def plot_industry_aggregates(
reform_params (OG-Core Specifications class): reform parameters
object
var_list (list): names of variable to plot

plot_type (string): type of plot, can be:
'pct_diff': plots percentage difference between baseline
and reform ((reform-base)/base)
Expand All @@ -209,6 +207,7 @@ def plot_industry_aggregates(
'levels': plot variables in model units
'forecast': plots variables in levels relative to baseline
economic forecast
stationarized (bool): whether used stationarized variables
num_years_to_plot (integer): number of years to include in plot
start_year (integer): year to start plot
forecast_data (array_like): baseline economic forecast series,
Expand Down Expand Up @@ -236,6 +235,14 @@ def plot_industry_aggregates(
assert base_params.start_year == reform_params.start_year
year_vec = np.arange(start_year, start_year + num_years_to_plot)
start_index = start_year - base_params.start_year
# Unstationarize variables if needed
if not stationarized:
for v in var_list:
base_tpi[v] = utils.unstationarize_vars(v, base_tpi, base_params)
if reform_tpi:
reform_tpi[v] = utils.unstationarize_vars(
v, reform_tpi, reform_params
)
# Check that reform included if doing pct_diff or diff plot
if plot_type == "pct_diff" or plot_type == "diff":
assert reform_tpi is not None
Expand Down
33 changes: 20 additions & 13 deletions ogcore/output_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ogcore.constants import VAR_LABELS, DEFAULT_START_YEAR
from ogcore import tax
from ogcore.utils import save_return_table, Inequality
from ogcore.utils import pct_change_unstationarized
from ogcore.utils import unstationarize_vars

cur_path = os.path.split(os.path.abspath(__file__))[0]

Expand Down Expand Up @@ -64,6 +64,13 @@ def macro_table(
assert base_params.start_year == reform_params.start_year
year_vec = np.arange(start_year, start_year + num_years)
start_index = start_year - base_params.start_year
if not stationarized:
for v in var_list:
base_tpi[v] = unstationarize_vars(v, base_tpi, base_params)
if reform_tpi:
reform_tpi[v] = unstationarize_vars(
v, reform_tpi, reform_params
)
# Check that reform included if doing pct_diff or diff plot
if output_type == "pct_diff" or output_type == "diff":
assert reform_tpi is not None
Expand All @@ -76,17 +83,7 @@ def macro_table(
for i, v in enumerate(var_list):
if output_type == "pct_diff":
# multiple by 100 so in percentage points
if stationarized:
results = ((reform_tpi[v] - base_tpi[v]) / base_tpi[v]) * 100
else:
pct_changes = pct_change_unstationarized(
base_tpi,
base_params,
reform_tpi,
reform_params,
output_vars=[v],
)
results = pct_changes[v] * 100
results = ((reform_tpi[v] - base_tpi[v]) / base_tpi[v]) * 100
results_years = results[start_index : start_index + num_years]
results_overall = (
(
Expand Down Expand Up @@ -452,11 +449,12 @@ def wealth_moments_table(
return table


def tp_output_dump_table(
def time_series_table(
base_params,
base_tpi,
reform_params=None,
reform_tpi=None,
stationarized=True,
table_format=None,
path=None,
):
Expand All @@ -471,6 +469,7 @@ def tp_output_dump_table(
reform_params (OG-Core Specifications class): reform parameters
object
reform_tpi (dictionary): TP output from reform run
stationarized (bool): whether to report stationarized output
table_format (string): format to return table in: 'csv', 'tex',
'excel', 'json', if None, a DataFrame is returned
path (string): path to save table to
Expand Down Expand Up @@ -501,6 +500,14 @@ def tp_output_dump_table(
"total_tax_revenue",
"business_tax_revenue",
]
# unstationarize variables if needed
if not stationarized:
for v in vars_to_keep:
base_tpi[v] = unstationarize_vars(v, base_tpi, base_params)
if reform_tpi:
reform_tpi[v] = unstationarize_vars(
v, reform_tpi, reform_params
)
base_dict = {k: base_tpi[k] for k in vars_to_keep}
# update key names
base_dict_final = dict(
Expand Down
Loading
Loading