-
-
Notifications
You must be signed in to change notification settings - Fork 132
Description
The ogcore.demographics module computes the population over the time path, but also needs the population distribution in the year before the time path begins. This is inferred and there seems to be an error constructing this when using certain population distributions (e.g., that from Ethiopia).
@claude is suggesting the following issues and fixes:
I've found the root cause of the infeasible growth rates. Here's
the complete analysis:
Root Cause: Backward Population Solver Produces Negative Values
The Problem:
When ogcore.demographics calculates the pre-period population (2023) by
solving backwards from 2024, it encounters a mathematical impossibility
with Ethiopia's demographic structure, particularly at very old ages
(93-99).
Why This Happens
The demographic equation is:
pop_current[age] = pop_previous[age-1] * survival_rate + pop_previous[age]
- imm_rate
When solving backwards for pop_previous[age]:
pop_previous[age] = (pop_current[age] - survived_from_previous_age) /
imm_rate
The bug occurs when:
- More people survive from age N-1 than exist at age N in the current
period - Immigration rate is positive
- Result: pop_previous[age] becomes hugely negative
Specific Examples from Ethiopia
At age 99:
- Current population (2024): 189 people
- People surviving from age 98: 365,692,350 (366 million!)
- Immigration rate: +19.9% (positive)
- Solved pre-population: -1.8 BILLION ❌
This creates a mathematical impossibility. The equation needs a negative
population to make the immigration math work, but negative populations
don't exist.
The Impact
This causes:
- 76 out of 80 working-age groups to have negative omega_S_preTP values
- omega_S_preTP ranges from -0.59 to +1.49 (should be all positive,
summing to 1.0) - Growth rate g_n[0] = -105.3% (< -100%, which is impossible)
Why Ethiopia but not South Africa?
Ethiopia has:
- Very young, rapidly growing population (high fertility)
- Steep population decline at old ages
- The backward solver hits this edge case
South Africa has:
- More balanced age distribution
- Slower population changes
- The backward solver works fine
Recommendations
demographics.py:1006-1033 - The pre_pop_solve() function needs to be
fixed. Options:
- Use actual historical data instead of solving backwards (best solution)
- Add constraints to prevent negative population values in the solver
- Use different immigration assumptions for backward vs forward solving
- Skip the backward solve and use forward data from get_pop() which
already retrieves 2023 data
The good news: The UN data itself is perfectly fine. This is purely an
ogcore.demographics implementation issue in how it initializes the
pre-transition period population.
cc @rickecon