From eae659894853196a28c43122841c5fcaaffa1d8a Mon Sep 17 00:00:00 2001 From: marcelolafleur Date: Mon, 23 Nov 2026 14:10:40 -0500 Subject: [PATCH 1/5] eta can vary over the time path Government transfers are shared out by eta, held at one age-by-group matrix in every year. As the population ages, each person's transfer then drifts away from its intended profile. eta now takes a (T+S) x S x J path, like omega and rho. An S x J matrix is still accepted and held constant over time, so existing inputs give the same model parameters, bit for bit. --- ogcore/default_parameters.json | 8 +++---- ogcore/parameters.py | 33 ++++++++++++++++++++++++++++ tests/test_parameters.py | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/ogcore/default_parameters.json b/ogcore/default_parameters.json index cdfd16e60..5f7e164bc 100644 --- a/ogcore/default_parameters.json +++ b/ogcore/default_parameters.json @@ -1755,12 +1755,12 @@ "param_notation": "$\\eta_{j,s,t}$", "section_1": "Fiscal Policy Parameters", "section_2": "Spending", - "notes": "This SxJ matrix gives the fraction of total aggregate transfers going to each age s and ability type j.", + "notes": "This (T+S)xSxJ array gives the fraction of total aggregate transfers going to each age s and ability type j in each period t; each period should sum to one. An SxJ matrix is also accepted and held constant over time; a path shorter than T+S is extended with its last period.", "type": "float", - "number_dims": 2, + "number_dims": 3, "value": [ { - "value": [ + "value": [[ [ 0.00395156539, 0.00395156539, @@ -2481,7 +2481,7 @@ 4.26755474e-05, 4.74172749e-06 ] - ] + ]] } ], "validators": { diff --git a/ogcore/parameters.py b/ogcore/parameters.py index 358683a22..066d877a8 100644 --- a/ogcore/parameters.py +++ b/ogcore/parameters.py @@ -117,6 +117,38 @@ def _rename_deprecated_params(revision): return revision +# Parameters stored by period, age and ability type, (T+S) x S x J, that +# also accept a single S x J matrix held constant over time +TIME_VARYING_SJ_PARAMS = ["eta"] + + +def _sj_to_time_path(revision): + """ + Wrap an S x J value of a parameter in ``TIME_VARYING_SJ_PARAMS`` as a + single period, so revisions written before the parameter could vary + over time still validate; ``extrapolate_array`` then holds it + constant over the time path. + + Args: + revision (dict): `PARAM: VALUE` pairs + + Returns: + revision (dict): the revision with such values wrapped; the + caller's dict is left unchanged + """ + wrap = [ + name + for name in TIME_VARYING_SJ_PARAMS + if name in revision and np.ndim(revision[name]) == 2 + ] + if not wrap: + return revision + revision = dict(revision) + for name in wrap: + revision[name] = [np.asarray(revision[name]).tolist()] + return revision + + class Specifications(paramtools.Parameters): """ Inherits ParamTools Parameters abstract base class. @@ -1066,6 +1098,7 @@ def update_specifications(self, revision, raise_errors=True): # a JSON string or a path to a JSON file revision = self.read_params(revision) revision = _rename_deprecated_params(revision) + revision = _sj_to_time_path(revision) # Pension regimes are a list of dicts, which paramtools cannot # validate, so set them aside and check them in # _build_cohort_pension_arrays (called by compute_default_params) diff --git a/tests/test_parameters.py b/tests/test_parameters.py index 818795d6c..6c8d8ae14 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -108,6 +108,45 @@ def test_tau_payroll_extended_over_T_and_J(): assert np.allclose(specs.tau_payroll[1, :], 0.2) +def test_eta_accepts_SxJ_or_time_path(): + # eta may vary over the time path, (T+S) x S x J, so transfers per + # person can keep their profile as the population ages; an S x J + # matrix is still accepted and held constant over time. + specs = Specifications() + TS, S, J = specs.T + specs.S, specs.S, specs.J + assert specs.eta.shape == (TS, S, J) + eta_SJ = specs.eta[-1].copy() + # S x J, as a list or an array, gives the same constant path + for value in (eta_SJ.tolist(), eta_SJ): + revision = {"eta": value} + specs = Specifications() + specs.update_specifications(revision) + assert np.array_equal(specs.eta, np.tile(eta_SJ, (TS, 1, 1))) + # the caller's revision is left as it was + assert np.ndim(revision["eta"]) == 2 + # a full path is used period by period; the steady state uses the + # last period + path = np.tile(eta_SJ, (TS, 1, 1)) + path[0] = np.ones((S, J)) / (S * J) + specs = Specifications() + specs.update_specifications({"eta": path.tolist()}) + assert np.allclose(specs.eta[0], 1 / (S * J)) + assert np.allclose(specs.eta[1:], eta_SJ) + # a shorter path is extended with its last period + specs = Specifications() + specs.update_specifications({"eta": path[:2].tolist()}) + assert specs.eta.shape == (TS, S, J) + assert np.allclose(specs.eta[0], 1 / (S * J)) + assert np.allclose(specs.eta[2:], eta_SJ) + # shares outside [0, 1] are still rejected + bad = eta_SJ.copy() + bad[0, 0] = -0.01 + for value in (bad.tolist(), [bad.tolist()]): + specs = Specifications() + with pytest.raises(Exception): + specs.update_specifications({"eta": value}) + + def test_TxJ_params_collapse_when_J_changes(): # A previously extrapolated T+S x J array that is uniform across J # should be re-extrapolated to the new J when J is changed, rather From 0bb2f2a447f5eee47253ba8a1260cb52927e6481 Mon Sep 17 00:00:00 2001 From: marcelolafleur Date: Mon, 23 Nov 2026 14:25:33 -0500 Subject: [PATCH 2/5] eta_RM can vary over the time path too; warn when shares do not sum to one Remittances are shared out by eta_RM the same way transfers are shared out by eta, so it gets the same (T+S) x S x J path. Older 2-D inputs, S x J or T x S, give the same model parameters as before. A warning now flags any period where eta or eta_RM does not sum to one, since households would then receive a different total than the aggregate. --- ogcore/default_parameters.json | 8 ++--- ogcore/parameters.py | 60 +++++++++++++++++++++++++--------- tests/test_parameters.py | 26 +++++++++++++++ 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/ogcore/default_parameters.json b/ogcore/default_parameters.json index 5f7e164bc..40e5c8584 100644 --- a/ogcore/default_parameters.json +++ b/ogcore/default_parameters.json @@ -2498,12 +2498,12 @@ "param_notation": "$\\eta_{RM,j,s,t}$", "section_1": "Household Parameters", "section_2": "Endowments", - "notes": "This SxJ matrix gives the fraction of total aggregate remittances going to each age s and ability type j.", + "notes": "This (T+S)xSxJ array gives the fraction of total aggregate remittances going to each age s and ability type j in each period t; each period should sum to one. An SxJ matrix is also accepted and held constant over time; a path shorter than T+S is extended with its last period.", "type": "float", - "number_dims": 2, + "number_dims": 3, "value": [ { - "value": [ + "value": [[ [ 0.00395156539, 0.00395156539, @@ -3224,7 +3224,7 @@ 4.26755474e-05, 4.74172749e-06 ] - ] + ]] } ], "validators": { diff --git a/ogcore/parameters.py b/ogcore/parameters.py index 066d877a8..23df2d6c0 100644 --- a/ogcore/parameters.py +++ b/ogcore/parameters.py @@ -119,33 +119,43 @@ def _rename_deprecated_params(revision): # Parameters stored by period, age and ability type, (T+S) x S x J, that # also accept a single S x J matrix held constant over time -TIME_VARYING_SJ_PARAMS = ["eta"] +TIME_VARYING_SJ_PARAMS = ["eta", "eta_RM"] -def _sj_to_time_path(revision): +def _sj_to_time_path(revision, S, T, J): """ - Wrap an S x J value of a parameter in ``TIME_VARYING_SJ_PARAMS`` as a - single period, so revisions written before the parameter could vary - over time still validate; ``extrapolate_array`` then holds it - constant over the time path. + Give a 2-D value of a parameter in ``TIME_VARYING_SJ_PARAMS`` the + 3-D shape its schema expects, so revisions written before the + parameter could vary over time still validate: an S x J matrix + becomes a single period, which ``extrapolate_array`` holds constant + over the time path, and a T x S or (T+S) x S path is split equally + across the J ability types, as ``extrapolate_array`` does. Args: revision (dict): `PARAM: VALUE` pairs + S (int): number of ages + T (int): number of periods in the time path + J (int): number of lifetime ability types Returns: - revision (dict): the revision with such values wrapped; the + revision (dict): the revision with such values reshaped; the caller's dict is left unchanged """ - wrap = [ - name - for name in TIME_VARYING_SJ_PARAMS - if name in revision and np.ndim(revision[name]) == 2 - ] - if not wrap: + reshaped = {} + for name in TIME_VARYING_SJ_PARAMS: + if name not in revision or np.ndim(revision[name]) != 2: + continue + value = np.asarray(revision[name], dtype=float) + if value.shape[0] == S: + reshaped[name] = value[np.newaxis, :, :].tolist() + elif value.shape[0] in (T, T + S): + reshaped[name] = ( + np.repeat(value[:, :, np.newaxis], J, axis=2) / J + ).tolist() + if not reshaped: return revision revision = dict(revision) - for name in wrap: - revision[name] = [np.asarray(revision[name]).tolist()] + revision.update(reshaped) return revision @@ -469,6 +479,19 @@ def compute_default_params(self): param_in, dims=(self.T + self.S, self.S, self.J), item=item ) setattr(self, item, param_out) + # each period of an allocation matrix should sum to one, or the + # transfers (remittances) households receive differ from the + # aggregate in the budget (resource constraint) + for item in TIME_VARYING_SJ_PARAMS: + sums = getattr(self, item).sum(axis=(1, 2)) + off = np.flatnonzero(np.abs(sums - 1.0) > 1e-6) + if off.size: + warnings.warn( + f"{item} does not sum to one in {off.size} of " + f"{sums.size} periods (first period {off[0]} sums to " + f"{sums[off[0]]:.6f}); households then receive a " + "different total than the aggregate" + ) # extrapolate SS demog objects demog_obj_to_SS = [ "omega_SS", @@ -1098,7 +1121,12 @@ def update_specifications(self, revision, raise_errors=True): # a JSON string or a path to a JSON file revision = self.read_params(revision) revision = _rename_deprecated_params(revision) - revision = _sj_to_time_path(revision) + revision = _sj_to_time_path( + revision, + revision.get("S", self.S), + revision.get("T", self.T), + len(revision.get("lambdas", self.lambdas)), + ) # Pension regimes are a list of dicts, which paramtools cannot # validate, so set them aside and check them in # _build_cohort_pension_arrays (called by compute_default_params) diff --git a/tests/test_parameters.py b/tests/test_parameters.py index 6c8d8ae14..ddc5dfe83 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -138,6 +138,12 @@ def test_eta_accepts_SxJ_or_time_path(): assert specs.eta.shape == (TS, S, J) assert np.allclose(specs.eta[0], 1 / (S * J)) assert np.allclose(specs.eta[2:], eta_SJ) + # a T x S path is still split equally across ability types + TxS = np.ones((specs.T, S)) / S + specs = Specifications() + specs.update_specifications({"eta": TxS.tolist()}) + assert specs.eta.shape == (TS, S, J) + assert np.allclose(specs.eta, 1 / (S * J)) # shares outside [0, 1] are still rejected bad = eta_SJ.copy() bad[0, 0] = -0.01 @@ -145,6 +151,26 @@ def test_eta_accepts_SxJ_or_time_path(): specs = Specifications() with pytest.raises(Exception): specs.update_specifications({"eta": value}) + # a period that does not sum to one is warned about + specs = Specifications() + with pytest.warns(UserWarning, match="eta does not sum to one"): + specs.update_specifications({"eta": (eta_SJ * 1.1).tolist()}) + + +def test_eta_RM_accepts_SxJ_or_time_path(): + # eta_RM shares out remittances as eta shares out transfers + specs = Specifications() + TS, S, J = specs.T + specs.S, specs.S, specs.J + assert specs.eta_RM.shape == (TS, S, J) + flat = np.ones((S, J)) / (S * J) + specs.update_specifications({"eta_RM": flat.tolist()}) + assert np.allclose(specs.eta_RM, flat) + path = np.tile(flat, (TS, 1, 1)) + path[0] = specs.eta[0] + specs = Specifications() + specs.update_specifications({"eta_RM": path.tolist()}) + assert np.allclose(specs.eta_RM[0], path[0]) + assert np.allclose(specs.eta_RM[1:], flat) def test_TxJ_params_collapse_when_J_changes(): From be2f13fc70e8122a9da3937f7c3645f1bda8e113 Mon Sep 17 00:00:00 2001 From: marcelolafleur Date: Mon, 23 Nov 2026 21:35:04 -0500 Subject: [PATCH 3/5] Changelog, version 0.25.3, and docs notes for eta and eta_RM over time --- CHANGELOG.md | 8 ++++++++ docs/book/content/intro/parameters.md | 2 +- docs/book/content/theory/households.md | 2 +- ogcore/__init__.py | 2 +- pyproject.toml | 2 +- uv.lock | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24bd01193..6bdb01127 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. 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.25.3] - 2026-11-23 + +### Added +- `eta` and `eta_RM`, which share out government transfers and remittances across ages and lifetime income groups, can now vary over time, as a (T+S) x S x J path like `omega` and `rho`. Before, each was one S x J matrix used in every year. As the population ages, holding that matrix fixed changes what each person receives: in an aging country the oldest households can end up receiving many times their intended transfer. A path lets a calibration keep each person's transfer on its intended profile in every year. +- An S x J matrix is still accepted and held constant over time, and the older T x S form of `eta_RM` is still accepted, so existing inputs give the same model parameters, bit for bit. A path shorter than T+S is extended with its last period. +- `Specifications` warns when `eta` or `eta_RM` does not sum to one in some period, since households would then receive a different total than the aggregate. +- Adds tests that both parameters accept either form and that an S x J matrix gives the same parameters as before. + ## [0.25.2] - 2026-11-23 ### Added diff --git a/docs/book/content/intro/parameters.md b/docs/book/content/intro/parameters.md index e977b294d..9f3d0f1da 100644 --- a/docs/book/content/intro/parameters.md +++ b/docs/book/content/intro/parameters.md @@ -121,7 +121,7 @@ _Out-of-Range Action:_ error #### `eta_RM` _Description:_ Matrix that allocates aggregate remittances across households. -_Notes:_ This SxJ matrix gives the fraction of total aggregate remittances going to each age s and ability type j. +_Notes:_ This (T+S)xSxJ array gives the fraction of total aggregate remittances going to each age s and ability type j in each period t; each period should sum to one. An SxJ matrix is also accepted and held constant over time; a path shorter than T+S is extended with its last period. _Value Type:_ float _Valid Range:_ min = 0.0 and max = 1.0 _Out-of-Range Action:_ error diff --git a/docs/book/content/theory/households.md b/docs/book/content/theory/households.md index 8caa8a8da..669b9e38c 100644 --- a/docs/book/content/theory/households.md +++ b/docs/book/content/theory/households.md @@ -244,7 +244,7 @@ In this section, we describe what is arguably the most important economic agent rm_{j,s,t} = \eta_{RM,j,s,t}\frac{RM_t}{\lambda_j\omega_{s,t}} \quad\forall \quad j,s,t ``` - The distribution object $\eta_{RM,j,s,t}$ is an $S\times J$ matrix in every period $t$ whose elements sum to one in every period. This object governs how total remittances in every period $RM_t$ are distributed as income among household budget constraints. + The distribution object $\eta_{RM,j,s,t}$ is an $S\times J$ matrix in every period $t$ whose elements sum to one in every period. This object governs how total remittances in every period $RM_t$ are distributed as income among household budget constraints. Both $\eta_{RM,j,s,t}$ and the transfer allocation $\eta_{j,s,t}$ below can be entered as a path over the time periods, or as a single $S\times J$ matrix held constant over time. (SecHHgovtransfers)= diff --git a/ogcore/__init__.py b/ogcore/__init__.py index 19b2469fd..6e1846568 100644 --- a/ogcore/__init__.py +++ b/ogcore/__init__.py @@ -21,4 +21,4 @@ from ogcore.txfunc import * # noqa: F403 from ogcore.utils import * # noqa: F403 -__version__ = "0.25.2" +__version__ = "0.25.3" diff --git a/pyproject.toml b/pyproject.toml index 0b0f0e86e..4541e4ee2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ogcore" -version = "0.25.2" +version = "0.25.3" authors = [ {name = "Jason DeBacker and Richard W. Evans"}, ] diff --git a/uv.lock b/uv.lock index d71c5388c..f830be339 100644 --- a/uv.lock +++ b/uv.lock @@ -2027,7 +2027,7 @@ wheels = [ [[package]] name = "ogcore" -version = "0.25.2" +version = "0.25.3" source = { editable = "." } dependencies = [ { name = "dask" }, From 50d238ba352ba4a6c1c69f93070de605ae09f00c Mon Sep 17 00:00:00 2001 From: marcelolafleur Date: Tue, 24 Nov 2026 13:33:04 -0500 Subject: [PATCH 4/5] Version 0.25.4 (#1279 takes 0.25.3) --- CHANGELOG.md | 3 ++- ogcore/__init__.py | 2 +- pyproject.toml | 2 +- uv.lock | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bdb01127..2dbe2127c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. 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.25.3] - 2026-11-23 +## [0.25.4] - 2026-11-24 ### Added - `eta` and `eta_RM`, which share out government transfers and remittances across ages and lifetime income groups, can now vary over time, as a (T+S) x S x J path like `omega` and `rho`. Before, each was one S x J matrix used in every year. As the population ages, holding that matrix fixed changes what each person receives: in an aging country the oldest households can end up receiving many times their intended transfer. A path lets a calibration keep each person's transfer on its intended profile in every year. @@ -950,6 +950,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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.25.4]: https://github.com/PSLmodels/OG-Core/compare/v0.25.3...v0.25.4 [0.25.2]: https://github.com/PSLmodels/OG-Core/compare/v0.25.1...v0.25.2 [0.25.1]: https://github.com/PSLmodels/OG-Core/compare/v0.25.0...v0.25.1 [0.25.0]: https://github.com/PSLmodels/OG-Core/compare/v0.24.6...v0.25.0 diff --git a/ogcore/__init__.py b/ogcore/__init__.py index 6e1846568..1d2a8d2d1 100644 --- a/ogcore/__init__.py +++ b/ogcore/__init__.py @@ -21,4 +21,4 @@ from ogcore.txfunc import * # noqa: F403 from ogcore.utils import * # noqa: F403 -__version__ = "0.25.3" +__version__ = "0.25.4" diff --git a/pyproject.toml b/pyproject.toml index 4541e4ee2..58b7d3aca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ogcore" -version = "0.25.3" +version = "0.25.4" authors = [ {name = "Jason DeBacker and Richard W. Evans"}, ] diff --git a/uv.lock b/uv.lock index f830be339..464618142 100644 --- a/uv.lock +++ b/uv.lock @@ -2027,7 +2027,7 @@ wheels = [ [[package]] name = "ogcore" -version = "0.25.3" +version = "0.25.4" source = { editable = "." } dependencies = [ { name = "dask" }, From d2b25b846c3a979a6c20c6c042767ccbc6d6ef1e Mon Sep 17 00:00:00 2001 From: marcelolafleur Date: Wed, 25 Nov 2026 17:27:12 -0500 Subject: [PATCH 5/5] Docs: the eta parameter entry describes the time path; CHANGELOG notes that a 2-D eta passed directly to adjust now fails validation --- CHANGELOG.md | 1 + docs/book/content/intro/parameters.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dbe2127c..ea9835a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - An S x J matrix is still accepted and held constant over time, and the older T x S form of `eta_RM` is still accepted, so existing inputs give the same model parameters, bit for bit. A path shorter than T+S is extended with its last period. - `Specifications` warns when `eta` or `eta_RM` does not sum to one in some period, since households would then receive a different total than the aggregate. - Adds tests that both parameters accept either form and that an S x J matrix gives the same parameters as before. +- A two-dimensional `eta` or `eta_RM` is converted to the new shape by `update_specifications`; passing one directly to paramtools' `adjust` now raises a validation error. ## [0.25.2] - 2026-11-23 diff --git a/docs/book/content/intro/parameters.md b/docs/book/content/intro/parameters.md index 9f3d0f1da..99886f626 100644 --- a/docs/book/content/intro/parameters.md +++ b/docs/book/content/intro/parameters.md @@ -627,7 +627,7 @@ _Out-of-Range Action:_ error #### `eta` _Description:_ Matrix that allocated government transfers across households. -_Notes:_ This SxJ matrix gives the fraction of total aggregate transfers going to each age s and ability type j. +_Notes:_ This (T+S)xSxJ array gives the fraction of total aggregate transfers going to each age s and ability type j in each period t; each period should sum to one. An SxJ matrix is also accepted and held constant over time; a path shorter than T+S is extended with its last period. _Value Type:_ float _Valid Range:_ min = 0.0 and max = 1.0 _Out-of-Range Action:_ error