Using the Fertility and Contraception Calendar Data

A survey redesign was implemented in 2019 PMA baseline surveys. The redesign included a longitudinal component and calendar data. The baseline samples in 2019 for Kenya, Nigeria, Democratic Republic of the Congo, and Burkina Faso contain calendar data variables, which are string variables containing 3 years of retrospective contraceptive calendar data. The strings are comma-delimited codes reading from January 2017 from right to left, with each code representing a month. Below is Stata code for making Kenya and Nigeria calendar variables easier to use. Code for the remaining countries and other statistical packages are forthcoming. The following are a key to the codes from these variables:

B
Birth
P
Pregnant
T
Pregnancy ended
0
No family planning method used
1
Female Sterilization
2
Male Sterilization
3
Implant
4
IUD
5
Injectables
7
Pill
8
Emergency Contraception
9
Male Condom
10
Female Condom
11
Diaphragm
12
Foam / Jelly
13
Standard Days / Cycle beads
14
LAM
30
Rhythm method
31
Withdrawal
39
Other traditional methods

Kenya 2019

Stata


*KENYA 2019*
clear
use "Z:\pma\reformatting\kenya\2019\hh\01_orig\ke2019a_hh_orig.dta"

set more off
gen calendar_temp = calendarke
gen length = strlen(calendar_temp)
gen last = strrpos(calendar_temp,",")
gen temp_string = ""


/*This forvalues loop iterates through January 2017 (Century month code 1405) up until November 2019 (Century month code 1439)
I stop short of December 2019 (CMC 1440) because some women were interviewed in November and have no record for December 2019.
I take care of December 2019 observations later
I read the entries from right to left, looking for anything contained between a comma and the end of the string.
Then I remove the entry I have read in and create a new string for the next iteration of the loop
*/
forvalues i = 1405(1)1439 {
gen preg`i' = 0
gen birth`i' = 0
gen method`i' = ""
gen nothing`i' = 0
gen term`i' = 0
*Read in the last character(s) in the string (after the comma)
replace temp_string = substr(calendar_temp,last+1,.)
*change variables depending on the value
replace preg`i' = 1 if temp_string == "P"
replace birth`i' = 1 if temp_string == "B"
//I think that a zero means that the woman is not using a method, not pregnant, did not give birth, and did not have a pregnancy end in this month
replace nothing`i' = 1 if temp_string == "0"
replace term`i' = 1 if temp_string == "T"
replace method`i' = temp_string if temp_string != "P" & temp_string != "B" & temp_string != "T" & temp_string != "0"
destring method`i', replace
*remove value from calendar_temp that we have read in
replace calendar_temp = substr(calendar_temp,1,last-1)
*find next comma and length
replace length = strlen(calendar_temp)
replace last = strrpos(calendar_temp,",")
}

//The only remaining pieces in calendar_temp contains information only women who were interviewed in December 2019 (CMC 1440)
gen preg1440 = 0
replace preg1440 = 1 if calendar_temp == "P"
gen birth1440 = 0
replace birth1440 = 1 if calendar_temp == "B"
gen method1440 = ""
replace method1440 = calendar_temp if calendar_temp != "P" & calendar_temp != "B" & calendar_temp != "T" & calendar_temp != "0"
destring method1440, replace
gen nothing1440 = 0
replace nothing1440 = 1 if calendar_temp == "0"
gen term1440 = 0
replace term1440 = 1 if calendar_temp == "T"


forvalues i = 1405(1)1440 {
replace preg`i' = 99 if calendarke == ""
replace birth`i' = 99 if calendarke == ""
replace method`i' = 99 if calendarke == ""
replace nothing`i' = 99 if calendarke == ""
replace term`i' = 99 if calendarke == ""
}
keep if eligible == 1
drop temp_string calendar_temp length last

//changes the shape of the data from wide to long
reshape long preg birth method nothing term, i(personid) j(cmc)
//CMC (Century-month code) is (Year - 1900)*12 + Month

//Recodes method numbers to align with other integrated variables
recode method (1=101) (2=102) (3=111) (4=112) (5=120) (7=131) (8=132) (9=141) (10=142) (11=151) (12=153) (13=160) (14=170) (30=210) (31=220) (39=240)
label define yes_no 0 "No" 1 "Yes" 99 "NIU (not in universe)"
label define methods 101 "Female Sterilization" 102 "Male Sterilization" 111 "Implants" 112 "IUD" 120 "Injectables" 121 "  Injectables (3 months)" 122 "  Injectables (monthly)" 131 "Pill" 132 "Emergency Contraception" 140 "Condom" 141 "  Male condom" 142 "  Female condom" 150 "Diaphragm/foam/jelly" 151 "  Diaphragm" 152 "  Foam" 153 "  Foam/Jelly" 160 "Standard Days/Cycle Beads Method" 170 "Lactational amenorrhea method (LAM)" 180 "N tablet" 199 "Other modern method" 200 "TRADITIONAL METHODS" 210 "Rhythm" 220 "Withdrawal" 230 "Washing " 240 "Other traditional"
label values method methods

label variable preg "Pregnant in time CMC"
label variable birth "Gave birth in time CMC"
label variable method "Used FP method in time CMC"
label variable term "Pregnancy ended in time CMC"
label variable nothing "Did not use FP, was not pregnant, or giving birth in time CMC"

foreach var of varlist preg birth nothing term {
label values `var' yes_no
}

Nigeria 2019

Below is example Stata code for converting the Nigeria 2019 calendar data into long form numeric data.

The Nigeria 2019 calendar data has an additional level of information. In addition to the contraceptive calendar, there is also a string variable that contains the reason the woman stopped using a family planning method (CALENDARNGWHY). The following code also extracts these data. See below the Stata code for the codes and labels for CALENDARNGWHY.

Codes for CALENDARNGWHY

1
Infrequent sex / husband away
2
Became pregnant while using
3
Wanted to become pregnant
4
Husband / partner disapproved
5
Wanted more effective method
6
Side effects / health concerns
7
Lack of access / too far
8
Costs too much
9
Inconvenient to use
10
Up to God / fatalistic
11
Difficult to get pregnant / menopausal
12
Marital dissolution / separation
96
Other

Stata


//There are women who have only commas rather than blank.  I'm preserving NIU cases for later, but I do want to make these string observations to be empty to not cause problems later
gen niu = 0
replace niu = 1 if calendar_c1_full == ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"
replace calendar_c1_full = "" if calendar_c1_full == ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"

gen calendar_temp = calendar_c1_full
gen length = strlen(calendar_temp)
gen last = strrpos(calendar_temp,",")
gen temp_string = ""

gen calendar_temp2 = substr(calendar_c2_full,1,37)
gen length2 = strlen(calendar_c2_full)
gen last2 = strrpos(calendar_c2_full,",")
gen temp_string2 = ""
/*This forvalues loop iterates through January 2017 (Century month code 1405) up until November 2019 (Century month code 1439)
I stop short of December 2019 (CMC 1440) because some women were interviewed in November and have no record for December 2019.
I take care of December 2019 observations later
I read the entries from right to left, looking for anything contained between a comma and the end of the string.
Then I remove the entry I have read in and create a new string for the next iteration of the loop
*/
forvalues i = 1405(1)1439 {
gen preg`i' = 0
gen birth`i' = 0
gen method`i' = ""
gen nothing`i' = 0
gen term`i' = 0
gen reason`i' = ""
*Read in the last character(s) in the string (after the comma)
replace temp_string = substr(calendar_temp,last+1,.)
replace temp_string2 = substr(calendar_temp2,last2+1,.)
*change variables depending on the value
replace preg`i' = 1 if temp_string == "P"
replace birth`i' = 1 if temp_string == "B"
replace nothing`i' = 1 if temp_string == "0"
replace term`i' = 1 if temp_string == "T"
replace method`i' = temp_string if temp_string != "P" & temp_string != "B" & temp_string != "T" & temp_string != "0"
destring method`i', replace
replace reason`i' = temp_string2 if temp_string != ""
destring reason`i', replace
*remove value from calendar_temp that we have read in
replace calendar_temp = substr(calendar_temp,1,last-1)
replace calendar_temp2 = substr(calendar_temp2,1,last2-1)
*find next comma and length
replace length = strlen(calendar_temp)
replace last = strrpos(calendar_temp,",")
replace length2 = strlen(calendar_temp2)
replace last2 = strrpos(calendar_temp2,",")
}

drop if FQmeta == ""
drop temp_string calendar_temp length last

//changes the shape of the data from wide to long
reshape long preg birth method nothing term reason, i(FQmetainstanceID) j(cmc)
//CMC (Century-month code) is (Year - 1900)*12 + Month

//Recodes method numbers to align with other integrated variables

recode method (1=101) (2=102) (3=111) (4=112) (5=120) (7=131) (8=132) (9=141) (10=142) (11=151) (12=153) (13=160) (14=170) (30=210) (31=220) (39=240)
label define yes_no 0 "No" 1 "Yes" 99 "NIU (not in universe)"
label define methods 101 "Female Sterilization" 102 "Male Sterilization" 111 "Implants" 112 "IUD" 120 "Injectables" 121 "  Injectables (3 months)" 122 "  Injectables (monthly)" 131 "Pill" 132 "Emergency Contraception" 140 "Condom" 141 "  Male condom" 142 "  Female condom" 150 "Diaphragm/foam/jelly" 151 "  Diaphragm" 152 "  Foam" 153 "  Foam/Jelly" 160 "Standard Days/Cycle Beads Method" 170 "Lactational amenorrhea method (LAM)" 180 "N tablet" 199 "Other modern method" 200 "TRADITIONAL METHODS" 210 "Rhythm" 220 "Withdrawal" 230 "Washing " 240 "Other traditional"
label values method methods
label define reasons 1 "Infrequent sex / husband away" 2 "Became pregnant while using" 3 "Wanted to become pregnant" 4 "Husband / partner disapproved" 5 "Wanted more effective method" 6 "Side effects / health concerns" 7 "Lack of access / too far" 8 "Costs too much" 9 "Inconvenient to use" 10 "Up to god / fatalistic" 11 "Difficult to get pregnant / menopausal" 12 "Marital dissolution / separation" 96 "Other"
label values reason reasons

label variable preg "Pregnant in time CMC"
label variable birth "Gave birth in time CMC"
label variable method "Used FP method in time CMC"
label variable term "Pregnancy ended in time CMC"
label variable nothing "Did not use FP, was not pregnant, or giving birth in time CMC"

foreach var of varlist preg birth nothing term {
replace `var' = 99 if niu == 1
label values `var' yes_no
}