| """ |
| Labor Productivity Dataset Generator for Sub-Saharan Africa |
| |
| Parameter Evidence Table: |
| | Parameter | Source | Year | Value | |
| |-----------|--------|------|-------| |
| | Labor productivity growth | ILO | 2023 | 2.1% | |
| | GDP per worker SSA | World Bank | 2023 | $8,200 | |
| | Agriculture productivity | FAO | 2023 | $3,800 | |
| | Manufacturing productivity | UNIDO | 2023 | $12,500 | |
| | Services productivity | World Bank | 2023 | $15,400 | |
| | Total factor productivity | UN | 2023 | 0.8% | |
| |
| 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)) |
| SECTORS = ["agriculture", "mining", "manufacturing", "construction", |
| "wholesale_retail", "transport", "services"] |
| FIRM_SIZES = ["micro", "small", "medium", "large"] |
|
|
|
|
| def dag_sample_productivity(node: str, parent_values: dict, rng: np.random.Generator, |
| year: int, country: str) -> any: |
| if node == "sector": |
| return rng.choice(SECTORS, p=[0.28, 0.04, 0.10, 0.06, 0.22, 0.08, 0.22]) |
| |
| elif node == "firm_size": |
| return rng.choice(FIRM_SIZES, p=[0.65, 0.20, 0.10, 0.05]) |
| |
| elif node == "technology_level": |
| sector = parent_values.get("sector", "services") |
| |
| if sector in ["manufacturing", "mining"]: |
| return rng.choice(["low", "medium", "high"], p=[0.35, 0.45, 0.20]) |
| elif sector in ["transport", "services"]: |
| return rng.choice(["low", "medium", "high"], p=[0.40, 0.40, 0.20]) |
| else: |
| return rng.choice(["low", "medium", "high"], p=[0.65, 0.28, 0.07]) |
| |
| elif node == "export_orientation": |
| sector = parent_values.get("sector", "services") |
| |
| if sector == "manufacturing": |
| return rng.choice(["none", "domestic", "export"], p=[0.45, 0.35, 0.20]) |
| elif sector == "agriculture": |
| return rng.choice(["none", "domestic", "export"], p=[0.55, 0.35, 0.10]) |
| else: |
| return rng.choice(["none", "domestic", "export"], p=[0.75, 0.20, 0.05]) |
| |
| return None |
|
|
|
|
| def calculate_productivity(parent_values: dict, rng: np.random.Generator, |
| year: int, country: str) -> float: |
| sector = parent_values.get("sector", "services") |
| firm_size = parent_values.get("firm_size", "small") |
| tech_level = parent_values.get("technology_level", "low") |
| export = parent_values.get("export_orientation", "none") |
| |
| sector_productivity = { |
| "agriculture": 3800, "mining": 25000, "manufacturing": 12500, |
| "construction": 8500, "wholesale_retail": 6500, "transport": 11000, |
| "services": 15400 |
| } |
| |
| firm_multipliers = {"micro": 0.45, "small": 0.75, "medium": 1.0, "large": 1.35} |
| tech_multipliers = {"low": 0.75, "medium": 1.0, "high": 1.45} |
| export_multipliers = {"none": 0.85, "domestic": 1.0, "export": 1.25} |
| |
| base = sector_productivity.get(sector, 10000) |
| base *= firm_multipliers.get(firm_size, 1.0) |
| base *= tech_multipliers.get(tech_level, 1.0) |
| base *= export_multipliers.get(export, 1.0) |
| |
| return base * rng.lognormal(0, 0.3) |
|
|
|
|
| def generate_labor_productivity_data( |
| scenario: Literal["low_burden", "moderate", "high_burden"], |
| seed: int, |
| country: str = None |
| ) -> pd.DataFrame: |
| """Generate labor productivity 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) |
| |
| sector = dag_sample_productivity("sector", {}, rng, year, cntry) |
| firm_size = dag_sample_productivity("firm_size", {}, rng, year, cntry) |
| |
| parent_values = {"sector": sector, "firm_size": firm_size} |
| tech_level = dag_sample_productivity("technology_level", parent_values, rng, year, cntry) |
| export = dag_sample_productivity("export_orientation", parent_values, rng, year, cntry) |
| |
| parent_values["technology_level"] = tech_level |
| parent_values["export_orientation"] = export |
| |
| productivity = calculate_productivity(parent_values, rng, year, cntry) |
| |
| records.append({ |
| "country": cntry, |
| "country_code": COUNTRY_CODES[cntry], |
| "year": year, |
| "sector": sector, |
| "firm_size": firm_size, |
| "technology_level": tech_level, |
| "export_orientation": export, |
| "labor_productivity_usd": round(productivity, 2), |
| "value_added_per_worker": round(productivity * 0.65, 2), |
| "output_per_hour": round(productivity / 2000, 2), |
| "scenario": scenario |
| }) |
| |
| df = pd.DataFrame(records) |
| df.attrs["seed"] = seed |
| df.attrs["scenario"] = scenario |
| df.attrs["source"] = "ILO, World Bank, FAO, UNIDO" |
| |
| return df |
|
|
|
|
| if __name__ == "__main__": |
| for scenario in ["low_burden", "moderate", "high_burden"]: |
| for seed in [42, 43, 44]: |
| df = generate_labor_productivity_data(scenario, seed) |
| filename = f"labor_productivity_{scenario}_seed{seed}.csv" |
| df.to_csv(filename, index=False) |
| print(f"Created {filename}: {len(df)} records") |
|
|