Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a demographics module in OG-Core #896

Merged
merged 46 commits into from
Feb 6, 2024
Merged

Conversation

jdebacker
Copy link
Member

This PR creates a demographic module in OG-Core. Such a module exists in the various country calibration repositories, but since all of those now use the UN population data, much of the code is repeated. Thus, moving the module here will remove redundant code across these country-specific repos.

In addition to this, the PR will add the following functionality:

  1. The ability for users to use the time-varying forecasts from the UN WPP, up to a user-specified end date (or the maximum date available from the UN).
  2. Users can enter their own custom forecasts of fertility, mortality, and immigration rates.
  3. Users can enter their own estimate of the initial population distribution (Note that doing 2 and 3 together will bypass the use of UN data and use demographics.py purely for filling out demographic variables over the transition path and in the SS).
  4. A country code parameter to specify which country's forecast to pull from the UN data.
  5. Streamlines the plotting utilities and allows users to return a Matplotlib figure object (not just save a plot image file to disk).

@jdebacker jdebacker marked this pull request as ready for review January 30, 2024 01:51
@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2024

Codecov Report

Attention: 54 lines in your changes are missing coverage. Please review.

Comparison is base (4b894bd) 80.26% compared to head (974eac0) 80.38%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #896      +/-   ##
==========================================
+ Coverage   80.26%   80.38%   +0.11%     
==========================================
  Files          18       19       +1     
  Lines        4175     4445     +270     
==========================================
+ Hits         3351     3573     +222     
- Misses        824      872      +48     
Flag Coverage Δ
unittests 80.38% <83.58%> (+0.11%) ⬆️

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

Files Coverage Δ
ogcore/SS.py 87.58% <ø> (-0.09%) ⬇️
ogcore/__init__.py 100.00% <ø> (ø)
ogcore/elliptical_u_est.py 100.00% <ø> (ø)
ogcore/execute.py 15.78% <ø> (ø)
ogcore/utils.py 88.35% <100.00%> (+0.44%) ⬆️
ogcore/firm.py 97.35% <75.00%> (ø)
ogcore/parameter_plots.py 80.86% <95.91%> (ø)
ogcore/txfunc.py 29.52% <0.00%> (ø)
ogcore/demographics.py 81.46% <81.46%> (ø)

@jdebacker
Copy link
Member Author

@rickecon All tests passing, including new ones. According to output from demographics.py pop distribution seems to converge. But I do see some odd stuff regarding immigration rates. A few plots to illustrate:

Fertility rates (look ok)

fert_rates_OG-Core

Mortality rates (look ok)

mort_rates_OG-Core

Immigration rates (too high at older ages)

imm_rates_OG-Core

Population distribution transition (see odd uptick at 100):

PopDistPath-OG-Core

Original vs Fixed SS population (odd uptick at 100 more apparent here):

OrigVsFixSSpop-OG-Core

I believe the uptick in the adjusted population distribution are a result of the high immigration rates at older ages. I will review the code that backs out these rates as residuals from the transition in the actual population distribution.

@jdebacker
Copy link
Member Author

With the latest commits, we are looking a lot better. Issue was that the UN data has a bin of 100+, who were being counted as age 100, creating a mass there. The module now drops those over age 99.

Updated plots:
OrigVsAdjImm
OrigVsFixSSpop
PopDistPath

@jdebacker
Copy link
Member Author

Plots looking good:

PopDistPath

@rickecon This PR is ready for your review. We'll want to merge this one before #897

@rickecon
Copy link
Member

rickecon commented Feb 6, 2024

@jdebacker. This is great. Merging.

@rickecon rickecon merged commit ba50ecc into PSLmodels:master Feb 6, 2024
11 checks passed
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.

3 participants