| """Generate African Mobile Subscriber Data for 15 SSA countries across 3 scenarios.""" |
|
|
| import csv |
| import json |
| import os |
| import random |
| from dataclasses import dataclass, field |
| from typing import Dict, List, Tuple |
|
|
| SEED = 42 |
| random.seed(SEED) |
|
|
| COUNTRIES = [ |
| "Nigeria", "South Africa", "Kenya", "Ghana", "Tanzania", |
| "Ethiopia", "Uganda", "Cote d'Ivoire", "Senegal", "Angola", |
| "Mozambique", "Rwanda", "Cameroon", "Madagascar", "Zambia", |
| ] |
|
|
| SCENARIOS = ["baseline", "5g_rollout", "market_saturation"] |
| RECORDS_PER_SCENARIO = 10000 |
|
|
| YEARS = [2024, 2025, 2026] |
| QUARTERS = ["Q1", "Q2", "Q3", "Q4"] |
|
|
| TECHNOLOGIES = ["2g", "3g", "4g", "5g"] |
|
|
| |
| OPERATOR_PROFILES: Dict[str, List[dict]] = { |
| "Nigeria": [ |
| {"name": "MTN Nigeria", "base_subscribers": 85.0, "base_market_share": 38.0, "base_arpu": 4.8}, |
| {"name": "Glo", "base_subscribers": 60.0, "base_market_share": 27.0, "base_arpu": 3.9}, |
| {"name": "Airtel Africa (Nigeria)", "base_subscribers": 55.0, "base_market_share": 25.0, "base_arpu": 4.2}, |
| {"name": "9mobile", "base_subscribers": 20.0, "base_market_share": 10.0, "base_arpu": 3.5}, |
| ], |
| "South Africa": [ |
| {"name": "MTN South Africa", "base_subscribers": 35.0, "base_market_share": 35.0, "base_arpu": 6.5}, |
| {"name": "Vodacom", "base_subscribers": 40.0, "base_market_share": 40.0, "base_arpu": 7.2}, |
| {"name": "Cell C", "base_subscribers": 12.0, "base_market_share": 12.0, "base_arpu": 4.8}, |
| {"name": "Telkom Mobile", "base_subscribers": 13.0, "base_market_share": 13.0, "base_arpu": 5.1}, |
| ], |
| "Kenya": [ |
| {"name": "Safaricom", "base_subscribers": 42.0, "base_market_share": 63.0, "base_arpu": 5.5}, |
| {"name": "Airtel Kenya", "base_subscribers": 18.0, "base_market_share": 27.0, "base_arpu": 3.2}, |
| {"name": "Telkom Kenya", "base_subscribers": 7.0, "base_market_share": 10.0, "base_arpu": 2.8}, |
| ], |
| "Ghana": [ |
| {"name": "MTN Ghana", "base_subscribers": 25.0, "base_market_share": 55.0, "base_arpu": 4.0}, |
| {"name": "Vodafone Ghana", "base_subscribers": 10.0, "base_market_share": 22.0, "base_arpu": 3.2}, |
| {"name": "AirtelTigo", "base_subscribers": 8.0, "base_market_share": 18.0, "base_arpu": 2.9}, |
| ], |
| "Tanzania": [ |
| {"name": "Vodacom Tanzania", "base_subscribers": 16.0, "base_market_share": 32.0, "base_arpu": 3.5}, |
| {"name": "Airtel Tanzania", "base_subscribers": 14.0, "base_market_share": 28.0, "base_arpu": 3.0}, |
| {"name": "Tigo Tanzania", "base_subscribers": 12.0, "base_market_share": 24.0, "base_arpu": 3.1}, |
| {"name": "Halotel", "base_subscribers": 5.0, "base_market_share": 10.0, "base_arpu": 2.5}, |
| {"name": "TTCL", "base_subscribers": 3.0, "base_market_share": 6.0, "base_arpu": 2.2}, |
| ], |
| "Ethiopia": [ |
| {"name": "Ethio Telecom", "base_subscribers": 70.0, "base_market_share": 85.0, "base_arpu": 2.8}, |
| {"name": "Safaricom Ethiopia", "base_subscribers": 12.0, "base_market_share": 15.0, "base_arpu": 3.5}, |
| ], |
| "Uganda": [ |
| {"name": "MTN Uganda", "base_subscribers": 16.0, "base_market_share": 50.0, "base_arpu": 2.9}, |
| {"name": "Airtel Uganda", "base_subscribers": 12.0, "base_market_share": 37.0, "base_arpu": 2.6}, |
| {"name": "Lycamobile Uganda", "base_subscribers": 2.0, "base_market_share": 6.0, "base_arpu": 2.1}, |
| ], |
| "Cote d'Ivoire": [ |
| {"name": "Orange Cote d'Ivoire", "base_subscribers": 16.0, "base_market_share": 47.0, "base_arpu": 3.4}, |
| {"name": "MTN Cote d'Ivoire", "base_subscribers": 12.0, "base_market_share": 35.0, "base_arpu": 3.1}, |
| {"name": "Moov Africa", "base_subscribers": 4.0, "base_market_share": 12.0, "base_arpu": 2.7}, |
| ], |
| "Senegal": [ |
| {"name": "Orange Senegal", "base_subscribers": 12.0, "base_market_share": 50.0, "base_arpu": 3.6}, |
| {"name": "Free Senegal", "base_subscribers": 6.0, "base_market_share": 25.0, "base_arpu": 2.8}, |
| {"name": "Expresso", "base_subscribers": 3.0, "base_market_share": 13.0, "base_arpu": 2.3}, |
| ], |
| "Angola": [ |
| {"name": "Unitel", "base_subscribers": 14.0, "base_market_share": 60.0, "base_arpu": 3.8}, |
| {"name": "Movicel", "base_subscribers": 6.0, "base_market_share": 26.0, "base_arpu": 3.0}, |
| ], |
| "Mozambique": [ |
| {"name": "Vodacom Mozambique", "base_subscribers": 10.0, "base_market_share": 42.0, "base_arpu": 2.8}, |
| {"name": "Movitel", "base_subscribers": 8.0, "base_market_share": 33.0, "base_arpu": 2.5}, |
| {"name": "Tmcel", "base_subscribers": 4.0, "base_market_share": 17.0, "base_arpu": 2.1}, |
| ], |
| "Rwanda": [ |
| {"name": "MTN Rwanda", "base_subscribers": 7.0, "base_market_share": 60.0, "base_arpu": 3.2}, |
| {"name": "Airtel Rwanda", "base_subscribers": 4.0, "base_market_share": 34.0, "base_arpu": 2.6}, |
| ], |
| "Cameroon": [ |
| {"name": "MTN Cameroon", "base_subscribers": 12.0, "base_market_share": 45.0, "base_arpu": 3.3}, |
| {"name": "Orange Cameroon", "base_subscribers": 10.0, "base_market_share": 37.0, "base_arpu": 3.1}, |
| {"name": "Nexttel", "base_subscribers": 3.0, "base_market_share": 11.0, "base_arpu": 2.4}, |
| ], |
| "Madagascar": [ |
| {"name": "Telma", "base_subscribers": 8.0, "base_market_share": 45.0, "base_arpu": 2.2}, |
| {"name": "Orange Madagascar", "base_subscribers": 6.0, "base_market_share": 34.0, "base_arpu": 2.5}, |
| {"name": "Airtel Madagascar", "base_subscribers": 3.0, "base_market_share": 17.0, "base_arpu": 2.0}, |
| ], |
| "Zambia": [ |
| {"name": "MTN Zambia", "base_subscribers": 9.0, "base_market_share": 48.0, "base_arpu": 3.1}, |
| {"name": "Airtel Zambia", "base_subscribers": 7.0, "base_market_share": 37.0, "base_arpu": 2.8}, |
| {"name": "Zamtel", "base_subscribers": 2.0, "base_market_share": 11.0, "base_arpu": 2.3}, |
| ], |
| } |
|
|
| |
| MOBILE_MONEY_FACTORS: Dict[str, float] = { |
| "Nigeria": 0.35, "South Africa": 0.08, "Kenya": 0.82, |
| "Ghana": 0.55, "Tanzania": 0.60, "Ethiopia": 0.20, |
| "Uganda": 0.65, "Cote d'Ivoire": 0.50, "Senegal": 0.45, |
| "Angola": 0.10, "Mozambique": 0.35, "Rwanda": 0.55, |
| "Cameroon": 0.30, "Madagascar": 0.25, "Zambia": 0.40, |
| } |
|
|
| |
| TECH_MIX: Dict[str, Dict[str, List[float]]] = {} |
| for c in COUNTRIES: |
| if c in ("South Africa", "Kenya", "Nigeria"): |
| TECH_MIX[c] = { |
| "baseline": [5, 25, 60, 10], |
| "5g_rollout": [3, 15, 52, 30], |
| "market_saturation": [4, 22, 62, 12], |
| } |
| elif c in ("Ghana", "Tanzania", "Rwanda", "Senegal"): |
| TECH_MIX[c] = { |
| "baseline": [10, 30, 55, 5], |
| "5g_rollout": [6, 20, 50, 24], |
| "market_saturation": [8, 28, 58, 6], |
| } |
| else: |
| TECH_MIX[c] = { |
| "baseline": [18, 35, 45, 2], |
| "5g_rollout": [10, 25, 50, 15], |
| "market_saturation": [15, 32, 48, 5], |
| } |
|
|
|
|
| def _scenario_multiplier(scenario: str, base: float) -> float: |
| if scenario == "baseline": |
| return base |
| elif scenario == "5g_rollout": |
| return base * 1.08 |
| else: |
| return base * 1.15 |
|
|
|
|
| def _scenario_subscribers(scenario: str, subs: float) -> float: |
| if scenario == "baseline": |
| return subs |
| elif scenario == "5g_rollout": |
| return subs * 0.95 |
| else: |
| return subs * 1.25 |
|
|
|
|
| def _rand_tech(tech_mix: List[float]) -> str: |
| return random.choices(TECHNOLOGIES, weights=tech_mix, k=1)[0] |
|
|
|
|
| def generate_records() -> List[dict]: |
| records = [] |
| record_id = 1 |
|
|
| for scenario in SCENARIOS: |
| for _ in range(RECORDS_PER_SCENARIO): |
| country = random.choice(COUNTRIES) |
| operators = OPERATOR_PROFILES[country] |
| op = random.choice(operators) |
| year = random.choice(YEARS) |
| quarter = random.choice(QUARTERS) |
|
|
| tech_mix = TECH_MIX[country][scenario] |
| technology = random.choices(TECHNOLOGIES, weights=tech_mix, k=1)[0] |
|
|
| subs_base = _scenario_subscribers(scenario, op["base_subscribers"]) |
| active_subscribers = round( |
| subs_base * random.uniform(0.85, 1.15), 2 |
| ) |
|
|
| arpu_base = _scenario_multiplier(scenario, op["base_arpu"]) |
| arpu = round(arpu_base * random.uniform(0.88, 1.12), 2) |
|
|
| churn = round(random.uniform(1.5, 6.5) if scenario != "market_saturation" else random.uniform(2.5, 8.0), 2) |
|
|
| prepaid_share = round(random.uniform(70, 98) if country != "South Africa" else random.uniform(45, 75), 2) |
|
|
| if technology in ("4g", "5g"): |
| data_rev = round(random.uniform(45, 75) if scenario != "market_saturation" else random.uniform(55, 82), 2) |
| else: |
| data_rev = round(random.uniform(20, 45), 2) |
| voice_rev = round(100 - data_rev, 2) |
|
|
| mm_factor = MOBILE_MONEY_FACTORS[country] |
| if country == "Kenya" and op["name"] == "Safaricom": |
| mm_factor = 0.82 |
| mm_subs = round(active_subscribers * mm_factor * random.uniform(0.7, 1.1), 2) |
|
|
| if technology == "5g": |
| data_usage = round(random.uniform(12, 35), 2) |
| elif technology == "4g": |
| data_usage = round(random.uniform(4, 15), 2) |
| elif technology == "3g": |
| data_usage = round(random.uniform(1, 5), 2) |
| else: |
| data_usage = round(random.uniform(0.2, 1.5), 2) |
|
|
| if scenario == "5g_rollout": |
| data_usage *= random.uniform(1.2, 1.6) |
|
|
| coverage = round(random.uniform(75, 99) if country in ("South Africa", "Kenya") else random.uniform(55, 92), 2) |
| if scenario == "5g_rollout" and technology == "5g": |
| coverage = round(random.uniform(30, 65), 2) |
|
|
| market_share = round(op["base_market_share"] * random.uniform(0.9, 1.1), 2) |
|
|
| if technology == "5g": |
| spectrum_eff = round(random.uniform(3.5, 5.0), 2) |
| elif technology == "4g": |
| spectrum_eff = round(random.uniform(2.0, 3.5), 2) |
| elif technology == "3g": |
| spectrum_eff = round(random.uniform(1.0, 2.0), 2) |
| else: |
| spectrum_eff = round(random.uniform(0.3, 1.0), 2) |
|
|
| satisfaction = round(random.uniform(3.0, 4.8) if country in ("South Africa", "Kenya", "Rwanda") else random.uniform(2.5, 4.2), 2) |
|
|
| records.append({ |
| "record_id": record_id, |
| "country": country, |
| "year": year, |
| "quarter": quarter, |
| "operator": op["name"], |
| "technology": technology, |
| "active_subscribers_millions": active_subscribers, |
| "arpu_usd": arpu, |
| "monthly_churn_pct": churn, |
| "prepaid_share_pct": prepaid_share, |
| "data_revenue_share_pct": data_rev, |
| "voice_revenue_share_pct": voice_rev, |
| "mobile_money_subscribers_millions": mm_subs, |
| "data_usage_gb_per_user": round(data_usage, 2), |
| "network_coverage_pct": coverage, |
| "market_share_pct": market_share, |
| "spectrum_efficiency_index": spectrum_eff, |
| "customer_satisfaction_score": satisfaction, |
| "scenario": scenario, |
| }) |
| record_id += 1 |
|
|
| random.shuffle(records) |
| return records |
|
|
|
|
| def write_csv(records: List[dict], path: str) -> None: |
| os.makedirs(os.path.dirname(path), exist_ok=True) |
| fieldnames = list(records[0].keys()) |
| with open(path, "w", newline="", encoding="utf-8") as f: |
| writer = csv.DictWriter(f, fieldnames=fieldnames) |
| writer.writeheader() |
| writer.writerows(records) |
|
|
|
|
| def write_jsonl(records: List[dict], path: str) -> None: |
| with open(path, "w", encoding="utf-8") as f: |
| for r in records: |
| f.write(json.dumps(r, ensure_ascii=False) + "\n") |
|
|
|
|
| def main(): |
| print("Generating 30,000 records across 15 SSA countries and 3 scenarios...") |
| records = generate_records() |
|
|
| csv_path = "telecom/african-mobile-subscriber-data/data/african_mobile_subscribers.csv" |
| jsonl_path = "telecom/african-mobile-subscriber-data/data/african_mobile_subscribers.jsonl" |
|
|
| write_csv(records, csv_path) |
| print(f" CSV: {csv_path} ({len(records)} rows)") |
|
|
| write_jsonl(records, jsonl_path) |
| print(f" JSONL: {jsonl_path} ({len(records)} rows)") |
|
|
| |
| countries_in_data = sorted(set(r["country"] for r in records)) |
| operators_in_data = sorted(set(r["operator"] for r in records)) |
| print(f"\nSummary:") |
| print(f" Countries: {len(countries_in_data)}") |
| print(f" Operators: {len(operators_in_data)}") |
| print(f" Scenarios: {SCENARIOS}") |
| print(f" Total records: {len(records)}") |
| for scenario in SCENARIOS: |
| count = sum(1 for r in records if r["scenario"] == scenario) |
| print(f" {scenario}: {count}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|