Skip to content

Commit 3cad5a0

Browse files
hmgaudeckerclaude
andcommitted
Derive current HIS from the regime name for result panels
Add aca_model.results.add_his_from_regime_name: the current health-insurance state is the regime a subject occupies, encoded as the leading token of the `{his}_{mc}_{ss}_{canwork}` regime name. `his` is not a per-subject model output, so it cannot be requested as a pylcm additional_target — downstream panels derive it from `regime_name` instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7af9682 commit 3cad5a0

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/aca_model/results.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Post-processing helpers for aca-model simulation result panels."""
2+
3+
import pandas as pd
4+
5+
6+
def add_his_from_regime_name(panel: pd.DataFrame) -> pd.DataFrame:
7+
"""Return `panel` with a `his` column derived from `regime_name`.
8+
9+
The current health-insurance state is not a per-subject model output — it is
10+
the regime a subject occupies. Regime names follow the
11+
`{his}_{mc}_{ss}_{canwork}` convention (see
12+
`aca_model.baseline.regimes.REGIME_SPECS`), so `his` is the leading
13+
underscore-delimited token of `regime_name`. The terminal `dead` regime has
14+
no HIS component and maps to `"dead"`, which no HIS moment selects.
15+
16+
Args:
17+
panel: Simulation result DataFrame carrying a `regime_name` column.
18+
19+
Returns:
20+
A copy of `panel` with an added string `his` column.
21+
22+
"""
23+
his = panel["regime_name"].astype("str").str.split("_", n=1).str[0].astype("str")
24+
return panel.assign(his=his)

tests/test_results.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pandas as pd
2+
from pandas.testing import assert_series_equal
3+
4+
from aca_model.results import add_his_from_regime_name
5+
6+
7+
def test_add_his_from_regime_name_extracts_leading_token():
8+
"""`his` is the leading token of `regime_name` (`{his}_{mc}_{ss}_{canwork}`).
9+
10+
The current health-insurance state is encoded as the first underscore-delimited
11+
component of the regime name; the terminal `dead` regime maps to `"dead"`.
12+
"""
13+
panel = pd.DataFrame(
14+
{
15+
"regime_name": pd.Categorical(
16+
[
17+
"retiree_nomc_inelig_canwork",
18+
"tied_dimc_choose_canwork",
19+
"nongroup_oamc_forced_forcedout",
20+
"dead",
21+
]
22+
),
23+
"value": [1.0, 2.0, 3.0, 4.0],
24+
}
25+
)
26+
27+
result = add_his_from_regime_name(panel)
28+
29+
assert_series_equal(
30+
result["his"],
31+
pd.Series(["retiree", "tied", "nongroup", "dead"], name="his"),
32+
)

0 commit comments

Comments
 (0)