The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » merging IR file with KR (Csection )
merging IR file with KR [message #16820] Wed, 06 March 2019 19:09 Go to next message
mmbah is currently offline  mmbah
Messages: 8
Registered: March 2019
Member
Dear Sir/ madam,

I wanted to calculate the total number of csection using the IR file for Malawi using the following commands:

use MWIR7HFL.dta

. gen csection=0

. replace csection=1 if m17_1==1 | m17_2==1 | m17_3==1 | m17_4==1 | m17_5==1 | m17_6==1
(976 real changes made)

tab csection

csection | Freq. Percent Cum.
------------+-----------------------------------
0 | 23,586 96.03 96.03
1 | 976 3.97 100.00
------------+-----------------------------------
Total | 24,562 100.00

However this is less than the total csection in the KR files


tab m17

delivery by |
caesarean |
section | Freq. Percent Cum.
------------+-----------------------------------
no | 16,122 93.53 93.53
yes | 1,116 6.47 100.00
------------+-----------------------------------
Total | 17,238 100.00


I tried to merge the IR and and the KR file so that I can use the m17 variable but loose lots of data in the merging process. I wanted someone to kindly help me calculated the total csection using the IR file or how to merge the m17 to the IR file


secondly.....

i calculate the number of stillbirths using the following commands:

use MWIR7HFL
gen stillbirths = regexm(vcal_1,"TPPPPPP")
label var stillbirths "stillbirths"

i obtained 213 stillbirths and the DHS final report indicated 236. Could someone help explained why and how to get the right values.

thanks for your kind help and understanding in advance
regards
Mamadou



Re: merging IR file with KR [message #16821 is a reply to message #16820] Thu, 07 March 2019 02:36 Go to previous messageGo to next message
Mlue
Messages: 92
Registered: February 2017
Location: North West
Senior Member
Hello Mamadou,

This is how I calculated the c-section births. I did not use the IR file, but instead used the BR file

FOR C-SECTION

clear all
set matsize 800
set maxvar 10000
set mem 1g
cd "..."
use "MWBR7HFL", clear
set more off

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

** WEIGHT VARIABLE
gen weight = v005/1000000

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

** SURVEY SET
gen psu =    v021
gen strata = v022
svyset psu [pw = weight], strata(strata)

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

// RENAME

rename v013 age
rename v106 education
rename v190 wealth
rename v025 residence
rename v024 region

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

** SKILLED BIRTH ATTENDANT
gen skilled_birth	=	0
label define skilled_birth 0"Unskilled" 1"Skilled"
label var skilled_birth "Birth delivered by skilled birth attendant"
label val skilled_birth skilled_birth

foreach xvar of varlist m3a m3b {
replace skilled_birth=1 if `xvar'==1
}
*

** PLACE OF DELIVERY
recode m15 (21/26 = 0 "Public sector") (31/36 = 1 "Private sector") ///
(11/12=2 "Home") (96=3 "Other") ///
(99=4 "Missing"), gen(delivery_place)
label var delivery_place "Place of delivery"
label val delivery_place delivery_place

** FACILITY DELIVERY
cap drop facility_delivery
recode delivery_place (0/1 = 1 "Facility births") (else=0 "Non-facility births"), gen(facility_delivery)
label var facility_delivery "Percentage delivered in a health facility"
label val facility_delivery facility_delivery

** CAESAREAN BIRTHS
recode m17 (1 = 1 "C-section") (else = 0 "Not c-section") , gen(c_section)
label var c_section " Birth delivered by C-section"
label val c_section c_section

** DECIDED BEFORE PAINS
recode m17a (1=1 "Yes") (else=0 "No"), gen(decided_before)
label var decided_before "Timing of decision to conduct C-section: Decided before onset of labour pains"
label val decided_before decided_before

** DECIDED AFTER PAINS
cap drop decided_after
recode m17a (2=1 "Yes") (else=0 "No"), gen(decided_after)
label var decided_after "Timing of decision to conduct C-section: Decided after onset of labour pains"
label val decided_after decided_after

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

** DROP IF NOT WITHIN SAMPLE
keep if m15 !=.

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

** CHECK
svy: tab wealth c_section, percent format(%9.1f) row
svy: tab wealth decided_before, percent format(%9.1f) row
svy: tab wealth decided_after, percent format(%9.1f) row

svy: tab wealth delivery_place, percent format(%9.1f) row
svy: tab wealth facility_delivery, percent format(%9.1f) row
svy: tab wealth skilled_birth, percent format(%9.1f) row

** ================ **

svy: tab wealth c_section, count format(%9.0f) miss
svy: tab wealth decided_before, count format(%9.0f) miss
svy: tab wealth decided_after, count format(%9.0f) miss

svy: tab wealth delivery_place, count format(%9.0f) miss
svy: tab wealth facility_delivery, count format(%9.0f) miss
svy: tab wealth skilled_birth, count format(%9.0f) miss

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

ssc install hplot, replace //Need internet connection
ssc install catplot, replace //Need internet connection

catplot c_section wealth [iw=weight], percent(wealth) stack asyvars ///
		bar(1, bcolor(gold*.6)) bar(2, bcolor(ltblue*.9)) bar(3, bcolor(red*.2)) ///
		blabel(bar, format(%9.1f) pos(center)) bar(4, bcolor(gs14)) ytitle(%) ///
		title(Percentage of births delivered by C-section) subtitle(Malawi DHS 2015-16)
	
catplot delivery_place wealth [iw=weight], percent(wealth) stack asyvars ///
		bar(1, bcolor(gold*.6)) bar(2, bcolor(ltblue*.9)) bar(3, bcolor(red*.2)) ///
		blabel(bar, format(%9.1f) pos(center) size(small) orientation(vert)) ///
		bar(4, bcolor(gs14)) ytitle(%) ///
		title(Percent distribution of births by place of delivery) ///
		subtitle(Malawi DHS 2015-16)

catplot facility_delivery wealth [iw=weight], percent(wealth) stack asyvars ///
		bar(1, bcolor(gold*.6)) bar(2, bcolor(ltblue*.9)) bar(3, bcolor(red*.2)) ///
		blabel(bar, format(%9.1f) pos(center)) bar(4, bcolor(gs14)) ytitle(%) ///
		title(Percentage of births by type of health facility) ///
		subtitle(Malawi DHS 2015-16)

catplot skilled_birth wealth [iw=weight], percent(wealth) stack asyvars ///
		bar(1, bcolor(gold*.6)) bar(2, bcolor(ltblue*.9)) bar(3, bcolor(red*.2)) ///
		blabel(bar, format(%9.1f) pos(center)) bar(4, bcolor(gs14)) ytitle(%) ///
		title(Percentage of births by type of provider) ///
		subtitle(Malawi DHS 2015-16)

exit

** <><><><><><><><><><><><><><><><><><>><><><><><><><><><><><><><><><><><><><> **

Re: merging IR file with KR [message #16822 is a reply to message #16820] Thu, 07 March 2019 02:54 Go to previous messageGo to next message
Mlue
Messages: 92
Registered: February 2017
Location: North West
Senior Member
This one might give you the total for stillbirths = 236

clear all
set matsize 800
set maxvar 10000
set mem 1g
cd "..."
use "MWIR7HFL", clear
set more off

**==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<> **

gen weight = v005/1000000
gen psu =    v021
gen strata = v023

**==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<> **

gen pregs = 0

forvalues i = 1/80 {
  gen cmc`i' = v017 + 80 - `i'
  gen event`i' = substr(vcal_1, `i', 1)
  gen type`i' = .
  replace type`i' = 1 if substr(vcal_1,`i',1) == "B"
  replace type`i' = 3 if substr(vcal_1,`i',1) == "T"
  replace type`i' = 2 if substr(vcal_1,`i',7) == "TPPPPPP" 
  replace pregs = pregs+1 if (substr(vcal_1,`i',1) == "B" | substr(vcal_1,`i',1) == "T")
}
*
* Drop cases with no pregnancies
drop if pregs == 0

* Decide what variables you want to keep first before the reshape, modify this list as you need to add extra variables.
keep caseid v001 v002 v003 v005 v008 v011 v013 v017 v018 v019 v021 v022 ///
v023 v024 v190 v025 v024 v106 pregs weight psu strata cmc* event* type* 

* The reshape is really really really slow if you don't select variables and cases first, and will most likely fail otherwise.
reshape long cmc event type, i(caseid) j(ix)

lab def type 1 "Birth" 2 "Stillbirth" 3 "Miscarriage/abortion"
lab val type type
lab var type "Type of pregnancy"
lab var cmc "Century month code of event"
lab var event "Calendar event code"

* Set length of calendar to use
gen callen = v018 + 59
* If calendar is aligned right (as in original dataset), use the following:
gen beg = v018
gen end = callen

* Include only the five year period
keep if ix >= beg & ix <= end

* keep only births and stillbirths
keep if type >= 1 & type <= 3

** =============== **
/*
cap drop stillbirth
recode type (2=1 "Stillbirth") (else=0 "Not stillbirth"), gen(stillbirth)
label var stillbirth "Stillbirths"
label val stillbirth stillbirth
*/

**==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<> **

svyset psu [pw = weight], strata(strata) vce(linearized)
*svydes

**==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<>==<> **

/** 
					NOTE: THIS DOES NOT MATCH THE OVERALL TOTAL FOR:
					(Number of pregnancies of 7+ months duration)
**/

*svy: tab v190 stillbirth, count format(%4.0f) miss
*svy: tab v190 stillbirth, percent format(%4.1f) row miss

svy: tab v190 type, count format(%4.0f) miss
svy: tab v190 type, percent format(%4.1f) row miss

exit

catplot type v190 [iw=weight], percent(v190) stack asyvars ///
		bar(1, bcolor(gold*.6)) bar(2, bcolor(ltblue*.9)) bar(3, bcolor(red*.2)) ///
		blabel(bar, format(%9.1f) pos(center) size(small) orientation(vert)) ///
		bar(4, bcolor(gs14)) ytitle(%) title(Percentage distribution of pregnancy type) ///
		subtitle(Malawi DHS 2015-16)
Re: merging IR file with KR [message #16828 is a reply to message #16821] Thu, 07 March 2019 09:06 Go to previous messageGo to next message
mmbah is currently offline  mmbah
Messages: 8
Registered: March 2019
Member
Dear MLUE,

Thank you very much for the wonder assistance which was very very helpful. I want to also calculated prenatal mortality and I used the following command.However, i am not sure I have calculated it right.

gen early_neonatal_deaths = 0
label var early_neonatal_deaths "earlyneo"
gen infant_deaths = 0

gen child_deaths = 0
label var child_deaths "child mortality"
label var infant_deaths "infant mortality"
* rename birth variables for use in forvalues loop
rename b*_0* b*_*

* Any early neonatal deaths, infant deaths, child deaths
forvalues b = 1/80 {
* early neonatal - days 0-6
replace early_neonatal_deaths = 1 if inrange(b6_`b',100,106)
}
gen wt = v005/1000000
replace wt = stillbirths*v005/1000000
replace wt = early_neonatal_deaths *v005/1000000
* perinatal mortality includes stillbirths and early neonatal deaths
gen perinatal_deaths = (stillbirths | early_neonatal_deaths)
label var perinatal_deaths "perinatal"

secondly I wants to run a logistic regression model to look at association between csection and perinatal mortality adjusting for demographics variables, morbidity, and ANC visits. could you help with graphs
Thank you very much for you kind assistance which is very well appreciated.

regards
Mamadou
Re: merging IR file with KR [message #17539 is a reply to message #16822] Wed, 10 April 2019 21:41 Go to previous message
mmbah is currently offline  mmbah
Messages: 8
Registered: March 2019
Member
Dear Mlue,

Thanks you very much for the codes as they are very helpful. I wanted to calculate the number of ealy neonatal mortality and perinatal mortality. However, when I reshape the data using the codes you provide i have over 150000 observations. If I calculate the early neonatal and perinatal deaths, bmi, parity using the below commands before or after the reshaping i get wrong estimation due to the high number of observation.I really need help.

replace end = v008
replace beg = v008-59

* rename b3 and b6 variables to facilitate use in the for loop
rename b3_0* b3_*
rename b6_0* b6_*

* Loop through birth history summing births and early neonatal deaths
* in the five years preceding the survey
forvalues i = 1/20 {
* restrict to 60 months preceding survey
replace births2 = births2+1 if inrange(b3_`i',beg,end)
replace earlyneo = earlyneo+1 if inrange(b3_`i',beg,end) & inrange(b6_`i',100,106)
}
gen perinatal = earlyneo+stillbirths
label variable perinatal "Perinatal mortality"

label define bmic 1"Underweight" 2"Normal" 3"Overweight/obese"
gen bmi= v445/100
label var bmi "bmi"
gen bmic= 1 if bmi<18.5
replace bmic=2 if bmi>=18.5 & bmi<25
replace bmic=3 if bmi>=25 & bmi!=.
label values bmic bmic
label var bmic "bmic"
tab bmic
rename v201 parity
recode parity 0/1=1 2=2 3=3 4=4 5/max=5
tab parity
label define paritylab 5"5+"
label var parity paritylab
label value parity paritylab
tab parity
Previous Topic: Merging all DHS recode files for one country in Stata
Next Topic: Merging IR and PR?
Goto Forum:
  


Current Time: Thu Mar 28 18:01:59 Coordinated Universal Time 2024