#!/usr/bin/env python3 """ Social Health Protection & Equity Dataset ============================================ Each record = ONE household's social health protection profile. Literature: WHO/ILO (2021) social protection in health. SSA: <20% population covered by any social protection. UHC monitoring: financial hardship indicators. Wagstaff et al. (2018) concentration indices for health service utilisation. WHO AFRO (2023): catastrophic spending concentrated among poorest quintiles. """ import numpy as np import pandas as pd import argparse import os SCENARIOS = { 'strong_protection': { 'exemplar': 'Rwanda/South Africa', 'social_protection_coverage': 0.65, 'health_insurance_coverage': 0.80, 'fee_exemption_coverage': 0.70, 'social_assistance_coverage': 0.40, 'catastrophic_rate': 0.06, 'impoverishment_rate': 0.03, 'concentration_index': -0.10, # pro-poor utilisation 'benefit_incidence_poorest': 0.22, 'utilisation_rate': 0.72, 'unmet_need_rate': 0.12, }, 'moderate_protection': { 'exemplar': 'Kenya/Ghana/Senegal', 'social_protection_coverage': 0.30, 'health_insurance_coverage': 0.25, 'fee_exemption_coverage': 0.35, 'social_assistance_coverage': 0.15, 'catastrophic_rate': 0.15, 'impoverishment_rate': 0.08, 'concentration_index': 0.10, # slightly pro-rich 'benefit_incidence_poorest': 0.14, 'utilisation_rate': 0.50, 'unmet_need_rate': 0.28, }, 'weak_protection': { 'exemplar': 'Nigeria/DRC/Chad', 'social_protection_coverage': 0.08, 'health_insurance_coverage': 0.05, 'fee_exemption_coverage': 0.10, 'social_assistance_coverage': 0.05, 'catastrophic_rate': 0.30, 'impoverishment_rate': 0.18, 'concentration_index': 0.30, # pro-rich 'benefit_incidence_poorest': 0.08, 'utilisation_rate': 0.30, 'unmet_need_rate': 0.50, }, } PROTECTION_TYPES = ['health_insurance', 'fee_exemption', 'cash_transfer', 'social_pension', 'disability_grant', 'food_assistance', 'none'] BARRIERS = ['cost', 'distance', 'quality', 'availability', 'discrimination', 'cultural', 'information', 'transport'] def generate_dataset(n=10000, seed=42, scenario='moderate_protection'): rng = np.random.default_rng(seed) sc = SCENARIOS[scenario] records = [] for idx in range(n): rec = {'id': idx + 1} rec['ses_quintile'] = int(rng.choice([1,2,3,4,5], p=[0.25,0.22,0.20,0.18,0.15])) rec['residence'] = rng.choice(['urban','rural'], p=[0.35,0.65]) rec['household_size'] = max(1, int(rng.poisson(5.0))) rec['head_sex'] = rng.choice(['male','female'], p=[0.60,0.40]) rec['head_age'] = int(np.clip(rng.normal(42,13), 18, 85)) rec['head_education'] = rng.choice(['none','primary','secondary','tertiary'], p=[0.25,0.35,0.28,0.12]) rec['has_disability'] = 1 if rng.random() < 0.08 else 0 rec['has_chronic_illness'] = 1 if rng.random() < 0.20 else 0 # Income income_base = {1:280, 2:550, 3:1100, 4:2400, 5:5500} rec['household_income_usd'] = max(50, int(rng.normal( income_base[rec['ses_quintile']], income_base[rec['ses_quintile']]*0.30))) # Social protection coverage sp_prob = sc['social_protection_coverage'] + (rec['ses_quintile']-3)*0.02 if rec['has_disability']: sp_prob += 0.10 sp_prob = np.clip(sp_prob, 0.01, 0.95) rec['has_social_protection'] = 1 if rng.random() < sp_prob else 0 if rec['has_social_protection']: pt_p = np.array([0.30, 0.20, 0.20, 0.10, 0.08, 0.10, 0.02]) pt_p = pt_p / pt_p.sum() rec['protection_type'] = rng.choice(PROTECTION_TYPES, p=pt_p) else: rec['protection_type'] = 'none' # Insurance ins_prob = sc['health_insurance_coverage'] + (rec['ses_quintile']-3)*0.04 rec['has_health_insurance'] = 1 if rng.random() < np.clip(ins_prob, 0.01, 0.98) else 0 # Utilisation util_prob = sc['utilisation_rate'] if rec['has_health_insurance']: util_prob += 0.15 if rec['ses_quintile'] <= 2: util_prob -= 0.08 if rec['residence'] == 'rural': util_prob -= 0.05 rec['sought_care'] = 1 if rng.random() < np.clip(util_prob, 0.10, 0.95) else 0 # OOP and financial protection if rec['sought_care']: base_oop = max(2, rng.lognormal(np.log(35), 0.8)) if rec['has_health_insurance']: base_oop *= 0.25 if rec['has_social_protection'] and rec['protection_type'] == 'fee_exemption': base_oop *= 0.10 rec['oop_spending_usd'] = round(base_oop, 2) else: rec['oop_spending_usd'] = round(max(0, rng.lognormal(np.log(8), 0.8)) if rng.random() < 0.3 else 0, 2) rec['catastrophic_expenditure'] = 1 if (rec['household_income_usd'] > 0 and rec['oop_spending_usd'] / rec['household_income_usd'] > 0.10) else 0 rec['impoverished_by_oop'] = 1 if (rec['household_income_usd'] >= 785 and (rec['household_income_usd'] - rec['oop_spending_usd']) < 785) else 0 # Unmet need rec['unmet_need'] = 0 rec['primary_barrier'] = 'none' if not rec['sought_care'] and rng.random() < sc['unmet_need_rate'] * 2: rec['unmet_need'] = 1 if rec['ses_quintile'] <= 2: b_p = np.array([0.40, 0.15, 0.10, 0.08, 0.05, 0.05, 0.07, 0.10]) else: b_p = np.array([0.15, 0.10, 0.25, 0.15, 0.05, 0.05, 0.10, 0.15]) b_p = b_p / b_p.sum() rec['primary_barrier'] = rng.choice(BARRIERS, p=b_p) # Equity metrics rec['benefit_incidence_score'] = round(np.clip( rng.normal(sc['benefit_incidence_poorest'] + (5-rec['ses_quintile'])*0.02, 0.05), 0, 0.40), 2) rec['financial_protection_score'] = round(np.clip( 0.3 * rec['has_health_insurance'] + 0.3 * rec['has_social_protection'] + 0.2 * (1 - rec['catastrophic_expenditure']) + 0.2 * (1 - rec['unmet_need']) + rng.normal(0, 0.05), 0, 1), 2) rec['year'] = rng.choice([2019,2020,2021,2022,2023], p=[0.12,0.18,0.20,0.25,0.25]) records.append(rec) df = pd.DataFrame(records) print(f"\n{'='*60}\nSocial Health Protection — {scenario} ({sc['exemplar']})") print(f" SP coverage: {df['has_social_protection'].mean()*100:.1f}%") print(f" Insurance: {df['has_health_insurance'].mean()*100:.1f}%") print(f" Catastrophic: {df['catastrophic_expenditure'].mean()*100:.1f}%") print(f" Unmet need: {df['unmet_need'].mean()*100:.1f}%") return df if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--all-scenarios', action='store_true') parser.add_argument('--n', type=int, default=10000) parser.add_argument('--seed', type=int, default=42) args = parser.parse_args() os.makedirs('data', exist_ok=True) if args.all_scenarios: for sc in SCENARIOS: df = generate_dataset(n=args.n, seed=args.seed, scenario=sc) df.to_csv(os.path.join('data', f'shp_{sc}.csv'), index=False) print(f" -> Saved\n") else: df = generate_dataset(n=args.n, seed=args.seed) df.to_csv(os.path.join('data', 'shp_moderate_protection.csv'), index=False)