* do e:\DHS\programs\perinatal_mortality\perinatal_mortality_do_16Aug2023.txt set more off /* Program to calculate perinatal mortality from the IR file Matches table 8.4 of the Malawi 2015-16 survey and other pre-DHS-8 surveys The construction of the pregnancy interval is omitted The interval for births (which may be neonatal deaths) goes from v008 to v008-59. births: births in the birth history in the past 60 months stillbirths: stillbirths ("TPPPPPP" sequences) in the calendar in the past 60 months earlyneo: early neonatal deaths (b6 is 100 to 106) in the birth history in the past 60 months Strategy construct a file of stillbirths and births from the calendar merge with the birth history for the same time period denominators: all births and stillbirths numeratoris: early neonatal deaths and stillbirths */ ********************************************************************** program define setup local lscratch_path=scratch_path keep v001 v002 v003 v005 v008 v011 v018 v021 v023 v024 v025 v106 v190 v224 bord* b3* b6* vcal_1 rename b*_0* b*_* * Find the formula that gives the cmc of entries in the calendar. Use b3 for the most recent * birth in the birth history (b3_1) and the column in the calendar of the most recent birth (call it B3) * This is needed in order to calculate the age of the woman at the time of a stillbirth gen B3=ustrpos(vcal_1,"B") regress b3_1 B3 if B3>0 & _n<100 matrix B=e(b) matrix list B scalar intercept=B[1,2] scalar list intercept drop B3 * the link is CMC=intercept-COL, where COL is the position in the calendar gen begin_cal = v018 gen end_cal = v018+59 gen begin_bh = v008-59 gen end_bh = v008 save "`lscratch_path'\\temp.dta", replace end ********************************************************************** program define make_pregnancy_history local lscratch_path=scratch_path * construct a file of stillbirths and births from the calendar, in a format similar to the birth history use "`lscratch_path'\\temp.dta", clear *drop b* local vcal_len = strlen(vcal_1[1]) * identify all B and T codes in the calendar by cmc * use PT=1 if the pregnancy termination is B, 2 if it is a stillbirth, 3 if it is any other termination, * otherwise 0; . if outside the range of the calendar for this woman gen events_1=0 gen events_2=0 gen events_3=0 quietly forvalues li = 1/`vcal_len' { gen cmc_`li'=intercept-`li' gen PT_`li'=. gen used_`li'=. replace PT_`li'=1 if substr(vcal_1,`li',1) == "B" replace PT_`li'=3 if substr(vcal_1,`li',1) == "T" replace PT_`li'=2 if substr(vcal_1,`li',7) == "TPPPPPP" replace used_`li'=0 if PT_`li'<. } * These lines could be built in earlier but are needed somewhere to stay within the date range quietly forvalues li = 1/`vcal_len' { replace PT_`li'=. if `li'end_cal replace used_`li'=. if `li'end_cal replace events_1=events_1+1 if PT_`li'==1 replace events_2=events_1+1 if PT_`li'==2 replace events_3=events_1+1 if PT_`li'==3 } tab1 events_* egen events=rownonmiss(PT*) summarize events scalar smax_events=r(max) * Go through each month of the calendar pulling out the events * Initialize Ptype and Pcmc local li=1 quietly while `li'<=smax_events { gen Ptype_`li'=. gen Pcmc_`li'=. local li=`li'+1 } * make smax_events passes through the calendar local k=1 while `k'<=smax_events { scalar sk=`k' scalar list sk gen change_`k'=0 local li=1 quietly while `li'<=`vcal_len' { scalar si=`li' replace Ptype_`k'=PT_`li' if PT_`li'<. & used_`li'==0 & change_`k'==0 replace Pcmc_`k'=cmc_`li' if PT_`li'<. & used_`li'==0 & change_`k'==0 replace change_`k'=1 if PT_`li'<. & used_`li'==0 & change_`k'==0 replace used_`li'=1 if PT_`li'<. & used_`li'==0 & Pcmc_`k'==cmc_`li' local li=`li'+1 } local k=`k'+1 } drop change* used* PT* cmc* b* * Need to get the intervals (preceding interval) between pregnancy terminations * The following code is just a place holder; it is not correct; I am not motivated at this time to figure it out (TP, 3May2019) local li=1 while `li'<=smax_events-1 { local liplus1=`li'+1 gen Pprevint_`li'=Pcmc_`li'-Pcmc_`liplus1' local li=`li'+1 } save "`lscratch_path'\\temp_preghist.dta", replace reshape long Ptype_ Pcmc_ Pprevint_, j(index) i(v001 v002 v003) rename P*_ P* keep if Ptype<=2 gen stillbirth=1 if Ptype==2 gen livebirth=1 if Ptype==1 drop Ptype rename Pcmc b3 drop index *cal* events gen in_births_and_stillbirths=1 sort v001 v002 v003 b3 * this is a file from the calendar with all births and stillbirths save "`lscratch_path'\\births_and_stillbirths_temp.dta", replace end ********************************************************************** program define make_neonatal local lscratch_path=scratch_path * construct file of neonatal deaths from the birth history use "`lscratch_path'\\temp.dta", clear keep v001 v002 v003 v005 v008 v011 v018 v021 v023 v024 v025 v106 v190 v224 b3* b6* gen begin_bh = v008-59 gen end_bh = v008 reshape long b3_ b6_ , j(bidx) i(v001 v002 v003) rename b*_ b* keep if b3>=begin_bh & b3<=end_bh gen earlyneo=0 replace earlyneo=1 if b6>=100 & b6<=106 label variable earlyneo "Early neonatal death" sort v001 v002 v003 b3 * this file includes all live births in the birth history during the interval corresponding to the window and identifies * early neonatal deaths save "`lscratch_path'\\neonatal_temp.dta", replace end ********************************************************************** program define make_combined_file_and_recodes * Merge the births and stillbirths from the calendar with the births in the birth history * After the merge, focus on the sillbirths and the early neonatal deaths local lscratch_path=scratch_path use "`lscratch_path'\\neonatal_temp.dta", clear merge v001 v002 v003 b3 using "`lscratch_path'\\births_and_stillbirths_temp.dta" keep if stillbirth==1 | _merge==3 drop _merge * calculate mother's age at birth gen age_at_event=int((b3-v011)/120) replace stillbirth=0 if stillbirth==. replace earlyneo=0 if earlyneo==. gen totpreg7m = stillbirth+earlyneo label variable totpreg7m "Pregnancy of 7+ months duration" gen perinatal = earlyneo+stillbirth label variable perinatal "Perinatal death" label variable age_at_event "Woman's age at (still)birth" label define age_at_event 1 "<20" 2 "20-29" 3 "30-39" 4 "40-49" label values age_at_event age_at_event * Note that this variable comes in from the stillbirths file but there it is set to 9999 rename Pprevint b11p gen prev_preg_int=. replace prev_preg_int=4 if b11p<. replace prev_preg_int=3 if b11p<39 replace prev_preg_int=2 if b11p<27 replace prev_preg_int=1 if b11p<15 replace prev_preg_int=0 if b11p==. svyset v021 [pweight=v005], strata(v023) singleunit(centered) save "`lscratch_path'\\combined_temp.dta", replace end ********************************************************************** program define make_output local lscratch_path=scratch_path use "`lscratch_path'\\combined_temp.dta", clear * get columns 1, 2, 3, and 4 of table 8.4 * svyset is used only for the perinatal rate tab stillbirth if stillbirth==1 [iweight=v005/1000000] tab earlyneo if earlyneo==1 [iweight=v005/1000000] summarize perinatal [iweight=v005/1000000] local lcovariates age_at_event prev_preg_int v025 v024 v106 v190 local lcovariates age_at_event v025 v024 v106 v190 foreach lcov of local lcovariates { tab `lcov' stillbirth if stillbirth==1 [iweight=v005/1000000] tab `lcov' earlyneo if earlyneo==1 [iweight=v005/1000000] svy: mean perinatal, over(`lcov') tab `lcov' [iweight=v005/1000000] } end ********************************************************************** program define main setup make_pregnancy_history make_neonatal make_combined_file_and_recodes make_output end ********************************************************************** ********************************************************************** ********************************************************************** ********************************************************************** ********************************************************************** * EXECUTION BEGINS HERE set more off scalar sdata_path="C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata" local ldata_path=sdata_path scalar scratch_path="e:\DHS\DHS_data\scratch" *use "`ldata_path'\\MWIR7AFL.DTA", clear *use "`ldata_path'\\LBIR7AFL.DTA", clear use "`ldata_path'\\ZMIR71FL.DTA", clear main