Skip to content

Commit

Permalink
estimate prop ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasrodes committed Dec 11, 2024
1 parent a258207 commit 1696b5d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
9 changes: 9 additions & 0 deletions etl/steps/data/garden/demography/2024-12-06/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,12 @@ def add_dim_some_education(tb):
def get_index_columns(tb):
cols_index = list(tb.columns.intersection(COLUMNS_INDEX))
return cols_index


def add_prop(tb):
# Add
tbx = tb[tb["education"] == "total"].drop(columns=["education", "assr"])
tb_sex_age_edu = tb.merge(tbx, on=["country", "year", "age", "sex", "scenario"], suffixes=["", "_total"])
tb_sex_age_edu["prop"] = 100 * tb_sex_age_edu["pop"] / tb_sex_age_edu["pop_total"]

return tb
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ tables:
with <%- if (education == "no_education") %>no education<%- elif (education == "some_education") %>some formal education<%- else %><<education>> education<%- endif %>
<%- endif %>
in a country or region.
description_processing: |-
We have estimated this indicator with the population values from this source.
presentation:
topic_tags:
- Global Education
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ tables:
with <%- if (education == "no_education") %>no education<%- if (education == "some_education") %>some formal education<%- else %><<education>> education<%- endif %>
<%- endif %>
in a country or region.
description_processing: |-
We have estimated this indicator with the population values from this source.
presentation:
topic_tags:
- Global Education
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from etl.helpers import PathFinder, create_dataset

from .shared import add_dim_some_education, make_table
from .shared import add_dim_some_education, add_prop, make_table

# Get paths and naming conventions for current step.
paths = PathFinder(__file__)
Expand Down Expand Up @@ -96,7 +96,7 @@ def run(dest_dir: str) -> None:
"age": "category",
"education": "category",
},
cols_single=["pop", "prop"],
cols_single=["pop"],
cols_range=["assr"],
per_1000=["pop"],
per_100=["assr"],
Expand All @@ -105,6 +105,9 @@ def run(dest_dir: str) -> None:
# Add education="some_education" (only for sex=total and age=total, and indicator 'pop')
tb_sex_age_edu = add_dim_some_education(tb_sex_age_edu)

# Add population share
tb_sex_age_edu = add_prop(tb_sex_age_edu)

#
# Save outputs.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ tables:
with <%- if (education == "no_education") %>no education<%- elif (education == "some_education") %>some formal education<%- else %><<education>> education<%- endif %>
<%- endif %>
in a country or region.
description_processing: |-
We have estimated this indicator with the population values from this source.
presentation:
topic_tags:
- Global Education
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from etl.helpers import PathFinder, create_dataset

from .shared import add_dim_some_education, make_table
from .shared import add_dim_some_education, add_prop, make_table

# Get paths and naming conventions for current step.
paths = PathFinder(__file__)
Expand Down Expand Up @@ -96,7 +96,7 @@ def run(dest_dir: str) -> None:
"age": "category",
"education": "category",
},
cols_single=["pop", "prop"],
cols_single=["pop"],
cols_range=["assr"],
per_1000=["pop"],
per_100=["assr"],
Expand All @@ -105,6 +105,9 @@ def run(dest_dir: str) -> None:
# Add education="some_education" (only for sex=total and age=total, and indicator 'pop')
tb_sex_age_edu = add_dim_some_education(tb_sex_age_edu)

# Add population share
tb_sex_age_edu = add_prop(tb_sex_age_edu)

#
# Save outputs.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
]

TABLES_CONCAT = [
("prop", "bprop"),
# ("prop", "bprop"),
("mys", "bmys"),
]
TABLES_DROP = []
Expand All @@ -69,7 +69,7 @@
# 2/ Age+Education dimensions. NOTE: no age=total, that's fine. We have tfr for all ages actually.
"by_age_edu": {"asfr"},
# 3/ Sex+Age+Education dimensions
"by_sex_age_edu": {"assr", "pop", "prop"},
"by_sex_age_edu": {"assr", "pop"},
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
]

TABLES_CONCAT = [
("prop", "bprop"),
# ("prop", "bprop"),
("mys", "bmys"),
]
TABLES_DROP = [
Expand Down Expand Up @@ -81,7 +81,7 @@
# 2/ Age+Education dimensions. NOTE: no age=total, that's fine. We have tfr for all ages actually.
"by_age_edu": {"asfr"},
# 3/ Sex+Age+Education dimensions
"by_sex_age_edu": {"assr", "pop", "prop"},
"by_sex_age_edu": {"assr", "pop"},
}


Expand Down

0 comments on commit 1696b5d

Please sign in to comment.