The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Dataset use in SPSS » Calculating cases for IYCF
Re: Calculating cases for IYCF [message #14987 is a reply to message #14985] Thu, 24 May 2018 04:48 Go to previous messageGo to previous message
Mlue
Messages: 92
Registered: February 2017
Location: North West
Senior Member
Hi Roselync,

Try this one, maybe it may help you replicate tables 11.2 and 11.3

FOR TABLE 11.2
/*
	USE THE CHILDREN'S RECODE: MWKR7HFL
	Malawi: Standard DHS, 2015-16
	
	BY: Mluleki Tsawe 
        {University of the Western Cape, South Africa}
	
	TO REPLICATE TABLE 11.2 - INITIAL BREASTFEEDING
*/

clear all
set matsize 800
set maxvar 10000
set mem 1g
cd "..." /*your path here...*/
use "MWKR7HFL", clear
set more off

********************************************************************************

** WEIGHT VARIABLE
gen weight = v005/1000000

********************************************************************************

** SURVEY SET
gen psu =    v021
gen strata = v023
svyset psu [pw = weight], strata(strata) vce(linearized)
*svydes

********************************************************************************

// RENAME

rename v013 age_woman
rename v106 education
rename v190 wealth
rename v025 residence
rename v024 region
*rename sdist district

////////////////////////////////////////////////////////////////////////////////

// GENERATING DEPENDENT VARIABLES

gen child_age=b19

recode child_age (0/1=1 "0-1") (2/3=2 "2-3") (4/5=3 "4-5") (6/8=4 "6-8") ///
(9/11=5 "9-11") (12/17=6 "12-17") (18/23=7 "18-23") (else=.), gen(child_age_grp)
svy: tab child_age_grp, count format(%4.0f)

* keep only children less than 2 years 
keep if child_age<24
*keep if b9==0* /* not needed for this table*/

* finding the youngest child living with the mother for each mother
bysort v001 v002 v003: egen minbidx=min(bidx)

* need to drop those that are bidx==2 and minbidx==1
drop if bidx>minbidx
/*keep if bidx <= minbidx*/

gen water=0
gen liquids=0
gen milk=0
gen solids=0
gen breast=0
gen bottle=0

*TO DETERMINE IF CHILD IS GIVEN WATER, SUGAR WATER, JUICE, TEA OR OTHER.
replace water=1 if (v409>=1 & v409<=7)
                                                                   
* IF GIVEN OTHER LIQUIDS
foreach xvar of varlist v409a v410 v410*  v413* {
replace liquids=1 if `xvar'>=1 & `xvar'<=7
}
*
cap replace liquids=1 if v412c>=1 & v412c<=7
                                                                                                
* IF GIVEN POWDER/TINNED milk, FORMULA OR FRESH milk
foreach xvar of varlist v411 v411a v412 v414p {
replace milk=1 if `xvar'>=1 & `xvar'<=7
}
*

* IF STILL BREASTFEEDING
replace breast=1 if m4==95 

* IF WAS EVER BOTTLE FED
replace bottle=1 if m38==1

gen bottle2=0
replace bottle2 = 1 if m38==1 & inrange(m4,93,99)
replace bottle2 = 0 if (m38==0 & m38==9) & inrange(m4,93,99)

*IF GIVEN ANY SOLID FOOD
foreach xvar of varlist v414* {
replace solids=1 if `xvar'>=1 & `xvar'<=7
}
*
replace solids=1 if v412a==1 | v412b==1 

cap drop diet            
gen diet=.
replace diet=0 if water==0 & liquids==0 & milk==0 & solids==0
replace diet=1 if water==1 & liquids==0 & milk==0 & solids==0
replace diet=2 if            liquids==1 & milk==0 & solids==0 
replace diet=3 if                         milk==1 & solids==0 
replace diet=4 if                         milk==0 & solids==1 
replace diet=5 if                         milk==1 & solids==1 
replace diet=6 if breast==0
 
label define diet 	0"given only water" 1"given only liquids" 2"given only milks" ///
3"given only solids" 4"given only milk and solids" 5"not still breastfeeding" ///
6"not now being breastfed" 7"What"
label var diet "Breastfeeding status1"
label val diet diet

*diet=0: given only water (full bf)
*diet=1: given only liquids (bf & liquids)
*diet=2: given only milks (bf & milk)
*diet=3: given only solids (bf & solids)
*diet=4: given only milk and solids (bf & milk & solids)
*diet=5: not still breastfeeding (weaned)
*diet=6: not now being breastfed (m4~=95)

gen ebf=0 
replace ebf=1 if diet==0 

******************************************

** FEEDING
gen feeding=1
replace feeding=2 if water==1
replace feeding=3 if liquids==1
replace feeding=4 if milk==1
replace feeding=5 if solids==1
replace feeding=0 if breast==0
label define feeding 0 "Not breastfeeding" 1 "exclusive breastfeeding" 2 "+Water" 3 "+Liquids" 4 "+Other Milk" 5 "+Solids"
label val feeding feeding

*creating the predominant breastfeeding variable. 
recode feeding (0 4 5=0) (1/3=1), gen(predom)

**********************************************
recode m4 (93 95=1 "Yes") (else=0 "No"), gen(ever_breastfed)
label var ever_breastfed "Ever breastfed"
label var ever_breastfed "Child ever breastfed?"
label val ever_breastfed ever_breastfed
svy: tab ever_breastfed, count format(%4.0f)
svy: tab ever_breastfed, percent format(%4.1f)

**********************************************

/** CHILD BREASTFED WITHIN ONE HOUR **/
recode m34 (0/100=1 "Yes") (else=0 "No"), gen(within_hour)
label var within_hour "Child put to breast within an hour?"
label val within_hour within_hour
svy: tab b4 within_hour, percent format(%4.1f) row

/** CHILD BREASTFED WITHIN ONE DAY **/
recode m34 (0/200=1 "Yes") (else=0 "No"), gen(within_one_day)
label var within_one_day "Child put to breast within one day?"
label val within_one_day within_one_day
svy: tab b4 within_one_day, percent format(%4.1f) row

**********************************************

*** DELIVERY
cap drop place_delivery
recode m15 (21/36=1 "Health facility") (11/12=2 "At home") ///
(else=3 "Other/Missing"), gen(place_delivery)
label var place_delivery "Place of delivery"
label val place_delivery place_delivery
svy: tab place_delivery within_one_day, percent format(%4.1f) row

** SKILLED BIRTH ATTENDANT
cap drop skilled_birth
gen skilled_birth	=	3
replace skilled_birth = 1 if (m3a==1 | m3b==1)
replace skilled_birth = 2 if m3g==1 & (m3b!=1)
replace skilled_birth = 4 if m3n==1
label define skilled_birth	1"Health professional" 2"Traditional birth attendant" ///
							3"Other" 4"No one"
label var skilled_birth "Birth delivered by skilled birth attendant"
label val skilled_birth skilled_birth
*tab skilled_birth [iw=weight], m
svy: tab skilled_birth ever_breastfed, percent format(%4.1f) row

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

** DROP IF NOT WITHIN SAMPLE
qui regr ever_breastfed if v208 !=0 [pw=weight]		
drop if e(sample)!=1

********************************************************************************

** CHECK: 

// Table 11.2 Percentage ever breastfed //

svy: tab b4 ever_breastfed, percent format(%4.1f) row
svy: tab skilled_birth ever_breastfed, percent format(%4.1f) row
svy: tab place_delivery ever_breastfed, percent format(%4.1f) row
svy: tab residence ever_breastfed, percent format(%4.1f) row
svy: tab region ever_breastfed, percent format(%4.1f) row
svy: tab education ever_breastfed, percent format(%4.1f) row
svy: tab wealth ever_breastfed, percent format(%4.1f) row

/*
svy: tab b4 ever_breastfed, count format(%4.0f)
svy: tab skilled_birth ever_breastfed, count format(%4.0f)
svy: tab place_delivery ever_breastfed, count format(%4.0f)
svy: tab residence ever_breastfed, count format(%4.0f)
svy: tab region ever_breastfed, count format(%4.0f)
svy: tab education ever_breastfed, count format(%4.0f)
svy: tab wealth ever_breastfed, count format(%4.0f)
*/

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

// Table 11.2 Percentage who started breastfeeding within 1 hour of birth //

svy: tab b4 within_hour, percent format(%4.1f) row
svy: tab skilled_birth within_hour, percent format(%4.1f) row
svy: tab place_delivery within_hour, percent format(%4.1f) row
svy: tab residence within_hour, percent format(%4.1f) row
svy: tab region within_hour, percent format(%4.1f) row
svy: tab education within_hour, percent format(%4.1f) row
svy: tab wealth within_hour, percent format(%4.1f) row

/*
svy: tab b4 within_hour, count format(%4.0f)
svy: tab skilled_birth within_hour, count format(%4.0f)
svy: tab place_delivery within_hour, count format(%4.0f)
svy: tab residence within_hour, count format(%4.0f)
svy: tab region within_hour, count format(%4.0f)
svy: tab education within_hour, count format(%4.0f)
svy: tab wealth within_hour, count format(%4.0f)
*/

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

// Table 11.2 Percentage who started breastfeeding within 1 day of birth //

svy: tab b4 within_one_day, percent format(%4.1f) row
svy: tab skilled_birth within_one_day, percent format(%4.1f) row
svy: tab place_delivery within_one_day, percent format(%4.1f) row
svy: tab residence within_one_day, percent format(%4.1f) row
svy: tab region within_one_day, percent format(%4.1f) row
svy: tab education within_one_day, percent format(%4.1f) row
svy: tab wealth within_one_day, percent format(%4.1f) row

/*
svy: tab b4 within_one_day, count format(%4.0f)
svy: tab skilled_birth within_one_day, count format(%4.0f)
svy: tab place_delivery within_one_day, count format(%4.0f)
svy: tab residence within_one_day, count format(%4.0f)
svy: tab region within_one_day, count format(%4.0f)
svy: tab education within_one_day, count format(%4.0f)
svy: tab wealth within_one_day, count format(%4.0f)
*/

exit



************************************************************ ***

FOR TABLE 11.3
clear all
set matsize 800
set maxvar 10000
set mem 1g
cd "..."
use "MWKR7HFL", clear
set more off

********************************************************************************

** WEIGHT VARIABLE
gen weight = v005/1000000

********************************************************************************

** SURVEY SET
gen psu =    v021
gen strata = v023
svyset psu [pw = weight], strata(strata) vce(linearized)
*svydes

********************************************************************************

// RENAME

rename v013 age_woman
rename v106 education
rename v190 wealth
rename v025 residence
rename v024 region
*rename sdist district

////////////////////////////////////////////////////////////////////////////////

// GENERATING DEPENDENT VARIABLES

gen child_age=b19

recode child_age (0/1=1 "0-1") (2/3=2 "2-3") (4/5=3 "4-5") (6/8=4 "6-8") ///
(9/11=5 "9-11") (12/17=6 "12-17") (18/23=7 "18-23") (else=.), gen(child_age_grp)
svy: tab child_age_grp, count format(%4.0f)

*keep if child_age_grp !=.

* keep only children less than 2 years 
keep if child_age<24
keep if b9==0

* finding the youngest child living with the mother for each mother
bysort v001 v002 v003: egen minbidx=min(bidx)

* need to drop those that are bidx==2 and minbidx==1
drop if bidx>minbidx
/*keep if bidx <= minbidx*/

gen water=0
gen liquids=0
gen milk=0
gen solids=0
gen breast=0
gen bottle=0

*TO DETERMINE IF CHILD IS GIVEN WATER, SUGAR WATER, JUICE, TEA OR OTHER.
replace water=1 if (v409>=1 & v409<=7)
                                                                   
* IF GIVEN OTHER LIQUIDS
foreach xvar of varlist v409a v410 v410*  v413* {
replace liquids=1 if `xvar'>=1 & `xvar'<=7
}
*
cap replace liquids=1 if v412c>=1 & v412c<=7
                                                                                                
* IF GIVEN POWDER/TINNED milk, FORMULA OR FRESH milk
foreach xvar of varlist v411 v411a v412 v414p {
replace milk=1 if `xvar'>=1 & `xvar'<=7
}
*

* IF STILL BREASTFEEDING
replace breast=1 if m4==95 

* IF WAS EVER BOTTLE FED
replace bottle=1 if m38==1

gen bottle2=0
replace bottle2 = 1 if m38==1 & inrange(m4,93,99)
replace bottle2 = 0 if (m38==0 & m38==9) & inrange(m4,93,99)

*IF GIVEN ANY SOLID FOOD
foreach xvar of varlist v414* {
replace solids=1 if `xvar'>=1 & `xvar'<=7
}
*
replace solids=1 if v412a==1 | v412b==1 

cap drop diet            
gen diet=.
replace diet=0 if water==0 & liquids==0 & milk==0 & solids==0
replace diet=1 if water==1 & liquids==0 & milk==0 & solids==0
replace diet=2 if            liquids==1 & milk==0 & solids==0 
replace diet=3 if                         milk==1 & solids==0 
replace diet=4 if                         milk==0 & solids==1 
replace diet=5 if                         milk==1 & solids==1 
replace diet=6 if breast==0
 
label define diet 	0"given only water" 1"given only liquids" 2"given only milks" ///
3"given only solids" 4"given only milk and solids" 5"not still breastfeeding" ///
6"not now being breastfed" 7"What"
label var diet "Breastfeeding status1"

*diet=0: given only water (full bf)
*diet=1: given only liquids (bf & liquids)
*diet=2: given only milks (bf & milk)
*diet=3: given only solids (bf & solids)
*diet=4: given only milk and solids (bf & milk & solids)
*diet=5: not still breastfeeding (weaned)
*diet=6: not now being breastfed (m4~=95)

gen ebf=0 
replace ebf=1 if diet==0 

******************************************

** FEEDING
gen feeding=1
replace feeding=2 if water==1
replace feeding=3 if liquids==1
replace feeding=4 if milk==1
replace feeding=5 if solids==1
replace feeding=0 if breast==0
label define feeding 0 "Not breastfeeding" 1 "exclusive breastfeeding" 2 "+Water" 3 "+Liquids" 4 "+Other Milk" 5 "+Solids"
label val feeding feeding

*creating the predominant breastfeeding variable. 
recode feeding (0 4 5=0) (1/3=1), gen(predom)
svy: tab predom if age<6, count percent format(%4.0f) col

**********************************************
/*recode m4 (93 95=1) (else=0), gen(ever_breastfed)
label var ever_breastfed "Ever breastfed"
label val ever_breastfed ever_breastfed*/

**********************************************

/** CHILD BREASTFED WITHIN ONE HOUR **/
*recode m34 (0/100=1 "Yes") (else=0 "No"), gen(within_hour)
*label var within_hour "Child put to breast within an hour?"
*label val within_hour within_hour
*svy: tab b4 within_hour, percent format(%4.1f) row

/** CHILD BREASTFED WITHIN ONE DAY **/
*recode m34 (0/200=1 "Yes") (else=0 "No"), gen(within_one_day)
*label var within_one_day "Child put to breast within one day?"
*label val within_one_day within_one_day
*svy: tab b4 within_one_day, percent format(%4.1f) row

**********************************************

*** DELIVERY
cap drop place_delivery
recode m15 (21/36=1 "Health facility") (11/12=2 "At home") ///
(else=3 "Other/Missing"), gen(place_delivery)
label var place_delivery "Place of delivery"
label val place_delivery place_delivery

** SKILLED BIRTH ATTENDANT
cap drop skilled_birth
gen skilled_birth	=	3
replace skilled_birth = 1 if (m3a==1 | m3b==1)
replace skilled_birth = 2 if m3g==1 & (m3b!=1)
replace skilled_birth = 4 if m3n==1
label define skilled_birth	1"Health professional" 2"Traditional birth attendant" ///
							3"Other" 4"No one"
label var skilled_birth "Birth delivered by skilled birth attendant"
label val skilled_birth skilled_birth

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

** DROP IF NOT WITHIN SAMPLE
qui regr feeding if v208 !=0 [pw=weight]		
drop if e(sample)!=1

********************************************************************************

** CHECK: Table 11.3 Breastfeeding status by age as in the report
svy: tab child_age_grp feeding, count format(%4.0f)
svy: tab child_age_grp feeding, percent format(%4.1f) row

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

exit

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Selecting one child per mother
Next Topic: Postnatal care utilization variable in 2015-2016 MDHS dataset
Goto Forum:
  


Current Time: Tue Mar 19 03:22:13 Coordinated Universal Time 2024