Skip to content

Start the population projection from the last year of population data - #1295

Open
arihantlodha-cmd wants to merge 1 commit into
PSLmodels:masterfrom
arihantlodha-cmd:pop-projection-from-last-data-year
Open

arihantlodha-cmd wants to merge 1 commit into
PSLmodels:masterfrom
arihantlodha-cmd:pop-projection-from-last-data-year

Conversation

@arihantlodha-cmd

Copy link
Copy Markdown
Contributor

What this fixes

get_pop_objs builds the population path from data years, then projects forward with constant rates:

pop_curr = pop_2D[T0 - 1, :]
omega_path_lev[:T0, :] = pop_2D[:T0, :]
for per in range(T0, T + S):
    pop_next = np.dot(OMEGA_orig, pop_curr)   # OMEGA_orig uses mort_rates[-1], imm_rates_orig[-1]

The population data have one more year than the rates, which map each year into the next. That is T0 + 1 years with user-provided data, and T0 + 2 with UN data, whose fertility, mortality, and immigration rates run from start_data_year to final_data_year, i.e. T0 + 1 years. With UN data, the first projected step (year T0 - 1 to T0) therefore uses mort_rates[-1] (= the year T0 rates), while the rho array the model aggregates with lists the year T0 - 1 rates for that step. imm_rates[T0 - 1] was solved to be consistent with the year T0 - 1 mortality. When mortality changes in the last data year, the population path breaks its own law of motion in that one period:

$$\omega_{t+1,s+1}(1+g_{n,t}) = \omega_{t,s}(1-\rho_{t,s}) + i_{t,s+1},\omega_{t,s+1}$$

This change starts the projection from the last data year (pop_2D[len_pop_dist - 1]), keeping all data years. With user-provided data, where the rates cover T0 years, the path is the same as before, because the old first step reproduced data year T0 exactly.

How it showed up

In OG-JPN (Japan, UN data, initial_data_year = start_year - 1), every transition had a resource-constraint error of 1.5e-3 of GDP in period 2, with the rest of the path below 1e-6 apart from the fixper period (#1290). Checking the law of motion on the model's own omega, rho, imm_rates, and g_n, the residual is 1e-17 in every period except t = 1 → 2 (1.9e-5) and the fixper period.

With this change, on the same calibration:

before after
law-of-motion residual, t = 1 → 2 1.9e-5 below 1e-17
RC error in period 2 (share of GDP) 1.5e-3 below 1e-6
RC error elsewhere, excluding fixper 3.8e-7 9.8e-7
largest change in Y, K, L, C, r, pension outlays along the path 0.06%

Tests

Adds test_pop_path_follows_its_law_of_motion. It mimics the UN path without network access, monkeypatching get_fert, get_mort, and get_pop to return rates for 3 years and population for 4, with mortality falling in the last year. It then checks the law of motion in every period before fixper to 1e-12. The test fails on master and passes with the change. The other non-local demographics tests pass.

The population data have one more year than the rates, but the projection
started from year T0 - 1, so with UN data it replaced data year T0 with a
step using the extrapolated rates while rho and imm_rates list the year
T0 - 1 rates. When mortality changes in the last data year the population
breaks its law of motion in that period, which shows up as a resource
constraint error in period 2 of the transition. Adds a test that the path
follows its law of motion in every period before fixper.
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.17%. Comparing base (11dd99b) to head (9baa5ea).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1295      +/-   ##
==========================================
+ Coverage   80.10%   80.17%   +0.06%     
==========================================
  Files          24       24              
  Lines        7208     7208              
==========================================
+ Hits         5774     5779       +5     
+ Misses       1434     1429       -5     
Flag Coverage Δ
unittests 80.17% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ogcore/demographics.py 73.61% <100.00%> (+0.77%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants