""" Poverty Headcount Africa Dataset Generator Parameter Evidence Table: | Parameter | Source | Value | Notes | |-----------|--------|-------|-------| | $2.15/day poverty line | World Bank | $2.15 | Extreme poverty threshold | | $3.00/day | World Bank 2024 | 46% of SSA | Current poverty rate | | $3.65/day | World Bank | - | Working poverty threshold | | $6.85/day | World Bank | - | Upper middle-income threshold | Countries: 15 African nations Years: 2018-2025 """ import numpy as np import pandas as pd from pathlib import Path COUNTRIES = [ "Nigeria", "Ethiopia", "Tanzania", "Kenya", "Uganda", "Mozambique", "Ghana", "Cote d'Ivoire", "Cameroon", "Senegal", "Zambia", "Malawi", "Rwanda", "Burkina Faso", "Mali" ] YEARS = list(range(2018, 2026)) BASE_RATES = { "below_2.15": 0.28, "below_3.00": 0.46, "below_3.65": 0.58, "below_6.85": 0.82 } COUNTRY_ADJUSTMENTS = { "Nigeria": {"below_2.15": 1.3, "below_3.00": 1.2, "below_3.65": 1.15, "below_6.85": 1.1}, "Ethiopia": {"below_2.15": 0.9, "below_3.00": 0.85, "below_3.65": 0.9, "below_6.85": 0.95}, "Tanzania": {"below_2.15": 0.85, "below_3.00": 0.9, "below_3.65": 0.9, "below_6.85": 0.9}, "Kenya": {"below_2.15": 0.6, "below_3.00": 0.55, "below_3.65": 0.5, "below_6.85": 0.45}, "Uganda": {"below_2.15": 0.75, "below_3.00": 0.8, "below_3.65": 0.85, "below_6.85": 0.9}, "Mozambique": {"below_2.15": 1.1, "below_3.00": 1.05, "below_3.65": 1.0, "below_6.85": 1.0}, "Ghana": {"below_2.15": 0.5, "below_3.00": 0.45, "below_3.65": 0.4, "below_6.85": 0.35}, "Cote d'Ivoire": {"below_2.15": 0.7, "below_3.00": 0.65, "below_3.65": 0.6, "below_6.85": 0.55}, "Cameroon": {"below_2.15": 0.8, "below_3.00": 0.75, "below_3.65": 0.7, "below_6.85": 0.65}, "Senegal": {"below_2.15": 0.65, "below_3.00": 0.6, "below_3.65": 0.55, "below_6.85": 0.5}, "Zambia": {"below_2.15": 0.9, "below_3.00": 0.85, "below_3.65": 0.8, "below_6.85": 0.75}, "Malawi": {"below_2.15": 1.0, "below_3.00": 0.95, "below_3.65": 0.9, "below_6.85": 0.85}, "Rwanda": {"below_2.15": 0.7, "below_3.00": 0.65, "below_3.65": 0.6, "below_6.85": 0.55}, "Burkina Faso": {"below_2.15": 0.85, "below_3.00": 0.8, "below_3.65": 0.75, "below_6.85": 0.7}, "Mali": {"below_2.15": 0.95, "below_3.00": 0.9, "below_3.65": 0.85, "below_6.85": 0.8} } def dag_sample(probabilities, n_samples, rng): """DAG-based sampling with probability weighting.""" indices = rng.choice(len(probabilities), size=n_samples, p=probabilities, replace=True) unique, counts = np.unique(indices, return_counts=True) return dict(zip(unique, counts)) def generate_dataset(scenario: str, seed: int) -> pd.DataFrame: """Generate poverty headcount dataset for Africa.""" np.random.seed(seed) rng = np.random.default_rng(seed) scenario_config = { "low_burden": {"n": 4000, "variance_scale": 0.8}, "moderate": {"n": 5000, "variance_scale": 1.0}, "high_burden": {"n": 6000, "variance_scale": 1.2} } config = scenario_config[scenario] n = config["n"] scale = config["variance_scale"] records = [] for year in YEARS: year_factor = 1.0 - (year - 2018) * 0.015 for country in COUNTRIES: adj = COUNTRY_ADJUSTMENTS[country] for threshold in ["below_2.15", "below_3.00", "below_3.65", "below_6.85"]: base_rate = BASE_RATES[threshold] adjusted_rate = min(0.99, base_rate * adj[threshold] * year_factor * scale) adjusted_rate = max(0.01, adjusted_rate) n_country_year = n // (len(YEARS) * len(COUNTRIES)) poverty_count = int(n_country_year * adjusted_rate) for _ in range(n_country_year): records.append({ "country": country, "year": year, "poverty_line": threshold, "headcount_ratio": adjusted_rate + rng.normal(0, 0.02 * scale), "population_below": poverty_count * 1000, "total_population": n_country_year * 1000 }) df = pd.DataFrame(records) df["headcount_ratio"] = df["headcount_ratio"].clip(0, 1) return df def main(): output_dir = Path(__file__).parent output_dir.mkdir(parents=True, exist_ok=True) scenarios = { "low_burden": 42, "moderate": 43, "high_burden": 44 } for scenario, seed in scenarios.items(): df = generate_dataset(scenario, seed) df.to_csv(output_dir / f"poverty_headcount_{scenario}.csv", index=False) print(f"Generated {scenario}: {len(df)} rows, seed={seed}") if __name__ == "__main__": main()