* do e:\DHS\programs\fertility_planning_status\fert_planning_do_8Feb2024.txt * Table 6.5, Fertility planning status * Revision for DHS-8, specifically for Kenya 2022 * Pregnancy outcomes in the past 3 years * Tom Pullum, February 2024 * v213 V213 currently pregnant * v214 duration of current pregnancy in months * v225 V225 current pregnancy wanted * m10 M10 wanted pregnancy when became pregnant (pregnancy-specific) set more off ********************************************************* program define reduce_IR_file rename *_0* *_* * Construct a new variable for each pregnancy, called pbord * pidxb is the index to the b variables. Use it to find bord for each pregnancy * Say that the most recent pregnancy, pregnancy #1, was not a live birth, and the previous pregnancy * was the most recent live birth. Then pidxb_1=. and pidxb_2=1. * We want to construct variables pbord_1=. and pbord_2=bord_1 * Thus pbord_p for pregnancy p will be bord for pregnancy p if the pregnancy outcome is a live * birth or this is a current pregnancy. Otherwise, pbord_p is . (NA) * Find the maximum number of pregnancies summarize pord_1 local lmax=r(max) quietly forvalues lo=1/`lmax' { gen pbord_`lo'=. forvalues lp=1/`lmax' { replace pbord_`lo'=bord_`lp' if pidxb_`lo'==`lp' } } keep caseid v005 v008 v011 v012 v201 v213 v214 v225 pbord_* pord_* p0_* p3_* p19_* p32_* m10_* save IRtemp.dta, replace end ************************************************************ program define reshape_births * construct a file of pregnancies use IRtemp.dta, clear reshape long pbord_ pord_ p0_ p3_ p19_ p32_ m10_, i(caseid) j(bidx) drop if pord==. rename *_ * * Restrict to the past 3 years keep if p19<36 * adjustment to birth order for multiple births; see Guide to DHS Statistics replace pbord=pbord-p0+1 if p0>1 * Construct intervals for the woman's age at birth (or other outcome) gen age_at_birth=-2 + int((p3-v011)/60) if p32==1 save IRtemp_births.dta, replace end ************************************************************ program define append_current_preg * construct a file of pregnancies use IRtemp.dta, clear keep caseid v005 v008 v011 v012 v201 v213 v214 v225 keep if v213==1 * Construct m10, bidx, birth order, and set p32 to 0 gen m10=v225 gen bidx=0 gen pbord=v201+1 gen p32=0 * tab v214,m gen preg_duration=v214 replace preg_duration=9 if v214>9 gen cmc_preg_delivery=v008+(9-preg_duration) gen age_at_birth=-2 + int((cmc_preg_delivery-v011)/60) * It can happen that a woman age 49 is pregnant and will give birth at age 50. Push any such cases into 45-49 replace age_at_birth=7 if age_at_birth>7 save IRtemp_pregs.dta, replace append using IRtemp_births.dta * The youngest age interval should include births before 15 replace age_at_birth=1 if age_at_birth<1 label define ab 1 "<20" 2 "20-24" 3 "25-29" 4 "30-34" 5 "35-39" 6 "40-44" 7 "45-49" label values age_at_birth ab label variable age_at_birth "Mother's age at birth" * Define a new label for p32 that includes a possible current pregnancy label define p32r 0 "Current pregnancy" 1 "Live birth" 2 "Stillbirth" 3 "Miscarriage" 4 "Abortion" label values p32 p32r label variable p32 "Pregnancy outcome type" gen birth_order=pbord replace birth_order=4 if pbord>4 label define bo 4 "4+" label values birth_order bo label variable birth_order "Birth order" label define m10 1 "Wanted then" 2 "Wanted later" 3 "Wanted no more" label values m10 m10 label variable m10 "Planning status" save IRtemp_births_plus_pregs.dta, replace end ************************************************************ program define construct_table use IRtemp_births_plus_pregs.dta, clear * Panel "LIVE BIRTHS AND CURRENT PREGNANCIES" tab birth_order m10 if p32<=1 [iweight=v005/1000000], row tab age_at_birth m10 if p32<=1 [iweight=v005/1000000], row * Panel "ALL PREGNANCY OUTCOMES" tab p32 m10 [iweight=v005/1000000], row end ************************************************************ ************************************************************ ************************************************************ ************************************************************ * EXECUTION BEGINS HERE use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\KEIR8BFL.DTA" , clear * Specify a workspace cd e:\DHS\DHS_data\scratch reduce_IR_file reshape_births append_current_preg construct_table