""" Labor Force Participation Rate Dataset Generator for Sub-Saharan Africa Parameter Evidence Table: | Parameter | Source | Year | Value | |-----------|--------|------|-------| | LFPR total SSA | ILO | 2023 | 67.2% | | Male LFPR | ILO | 2023 | 73.8% | | Female LFPR | ILO | 2023 | 60.9% | | Youth LFPR 15-24 | ILO | 2023 | 52.4% | | Urban LFPR | World Bank | 2023 | 72.1% | | Rural LFPR | World Bank | 2023 | 64.5% | | Gender gap LFPR | ILO | 2023 | 12.9pp | Countries: Nigeria, Kenya, Ethiopia, Ghana, South Africa, Tanzania, Uganda, Rwanda, Mozambique, Zambia, Malawi, Senegal, Ivory Coast, Cameroon, Burkina Faso Years: 2018-2025 Scenarios: low_burden (n=4000), moderate (n=5000), high (n=6000) Seeds: 42, 43, 44 """ import numpy as np import pandas as pd from typing import Literal COUNTRIES = [ "Nigeria", "Kenya", "Ethiopia", "Ghana", "South Africa", "Tanzania", "Uganda", "Rwanda", "Mozambique", "Zambia", "Malawi", "Senegal", "Ivory Coast", "Cameroon", "Burkina Faso" ] COUNTRY_CODES = { "Nigeria": "NGA", "Kenya": "KEN", "Ethiopia": "ETH", "Ghana": "GHA", "South Africa": "ZAF", "Tanzania": "TZA", "Uganda": "UGA", "Rwanda": "RWA", "Mozambique": "MOZ", "Zambia": "ZMB", "Malawi": "MWI", "Senegal": "SEN", "Ivory Coast": "CIV", "Cameroon": "CMR", "Burkina Faso": "BFA" } YEARS = list(range(2018, 2026)) GENDERS = ["male", "female"] AGE_GROUPS = ["15-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54", "55-59", "60-64"] URBAN_RURAL = ["urban", "rural"] EDUCATION_LEVELS = ["none", "primary", "secondary", "tertiary"] def dag_sample_lfpr(node: str, parent_values: dict, rng: np.random.Generator, year: int, country: str) -> any: if node == "lfp_status": gender = parent_values.get("gender", "male") age_group = parent_values.get("age_group", "25-29") urban_rural = parent_values.get("urban_rural", "urban") base_rate = 0.672 if gender == "female": base_rate -= 0.063 else: base_rate += 0.066 if "15-19" in age_group: base_rate -= 0.25 elif "20-24" in age_group: base_rate -= 0.10 elif "60-64" in age_group: base_rate -= 0.15 if urban_rural == "rural": base_rate -= 0.076 base_rate = max(0.3, min(0.85, base_rate)) if rng.random() < base_rate: return "in_labor_force" else: return "not_in_labor_force" elif node == "labor_force_status": lfp = parent_values.get("lfp_status", "in_labor_force") if lfp == "not_in_labor_force": return rng.choice(["student", "homemaker", "retired", "discouraged", "other_inactive"], p=[0.25, 0.35, 0.10, 0.15, 0.15]) else: return rng.choice(["employed", "unemployed"], p=[0.88, 0.12]) elif node == "employment_type": emp_status = parent_values.get("labor_force_status", "employed") if emp_status != "employed": return "not_applicable" return rng.choice(["full_time", "part_time", "self_employed", "casual"], p=[0.45, 0.15, 0.30, 0.10]) elif node == "work_hours": emp_type = parent_values.get("employment_type", "full_time") if emp_type == "full_time": return rng.choice(list(range(35, 50))) elif emp_type == "part_time": return rng.choice(list(range(1, 35))) else: return rng.choice(list(range(20, 60))) return None def generate_labor_force_participation_data( scenario: Literal["low_burden", "moderate", "high_burden"], seed: int, country: str = None ) -> pd.DataFrame: """Generate labor force participation dataset for SSA.""" n_samples = {"low_burden": 4000, "moderate": 5000, "high_burden": 6000}[scenario] rng = np.random.default_rng(seed) if country: countries = [country] else: countries = COUNTRIES records = [] samples_per_country = n_samples // len(countries) for cntry in countries: for _ in range(samples_per_country): year = rng.choice(YEARS) gender = rng.choice(GENDERS) age_group = rng.choice(AGE_GROUPS) urban_rural = rng.choice(URBAN_RURAL) education = rng.choice(EDUCATION_LEVELS) parent_values = { "gender": gender, "age_group": age_group, "urban_rural": urban_rural } lfp_status = dag_sample_lfpr("lfp_status", parent_values, rng, year, cntry) parent_values["lfp_status"] = lfp_status lf_status = dag_sample_lfpr("labor_force_status", parent_values, rng, year, cntry) parent_values["labor_force_status"] = lf_status emp_type = dag_sample_lfpr("employment_type", parent_values, rng, year, cntry) parent_values["employment_type"] = emp_type work_hours = dag_sample_lfpr("work_hours", parent_values, rng, year, cntry) records.append({ "country": cntry, "country_code": COUNTRY_CODES[cntry], "year": year, "gender": gender, "age_group": age_group, "urban_rural": urban_rural, "education_level": education, "in_labor_force": lfp_status == "in_labor_force", "labor_force_status": lf_status, "employment_type": emp_type, "weekly_hours": work_hours, "is_underemployed": work_hours < 35 if work_hours else False, "scenario": scenario }) df = pd.DataFrame(records) df.attrs["seed"] = seed df.attrs["scenario"] = scenario df.attrs["source"] = "ILO, World Bank" return df if __name__ == "__main__": for scenario in ["low_burden", "moderate", "high_burden"]: for seed in [42, 43, 44]: df = generate_labor_force_participation_data(scenario, seed) filename = f"labor_force_participation_{scenario}_seed{seed}.csv" df.to_csv(filename, index=False) print(f"Created {filename}: {len(df)} records")