Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ 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.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.
- 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

### Added
Expand Down Expand Up @@ -942,6 +951,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
Expand Down
4 changes: 2 additions & 2 deletions docs/book/content/intro/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/book/content/theory/households.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)=
Expand Down
2 changes: 1 addition & 1 deletion ogcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
from ogcore.txfunc import * # noqa: F403
from ogcore.utils import * # noqa: F403

__version__ = "0.25.2"
__version__ = "0.25.4"
16 changes: 8 additions & 8 deletions ogcore/default_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2481,7 +2481,7 @@
4.26755474e-05,
4.74172749e-06
]
]
]]
}
],
"validators": {
Expand All @@ -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,
Expand Down Expand Up @@ -3224,7 +3224,7 @@
4.26755474e-05,
4.74172749e-06
]
]
]]
}
],
"validators": {
Expand Down
61 changes: 61 additions & 0 deletions ogcore/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,48 @@ 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", "eta_RM"]


def _sj_to_time_path(revision, S, T, J):
"""
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 reshaped; the
caller's dict is left unchanged
"""
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)
revision.update(reshaped)
return revision


class Specifications(paramtools.Parameters):
"""
Inherits ParamTools Parameters abstract base class.
Expand Down Expand Up @@ -437,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",
Expand Down Expand Up @@ -1066,6 +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.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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "ogcore"
version = "0.25.2"
version = "0.25.4"
authors = [
{name = "Jason DeBacker and Richard W. Evans"},
]
Expand Down
65 changes: 65 additions & 0 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,71 @@ 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)
# 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
for value in (bad.tolist(), [bad.tolist()]):
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():
# 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
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading