|
| 1 | +/******************************************************************************************************************************* |
| 2 | +Program: PregOutcomes.do |
| 3 | +Purpose: Calculate pregnancy outcomes (Births, Miscarriages, Abortions, Stillbirths) |
| 4 | +Author: Tom Pullum |
| 5 | +Date last modified: Feb 9, 2023 by Tom Pullum |
| 6 | + July 18, 2023 by Shireen Assaf to adapat code and add more notes for this project |
| 7 | +
|
| 8 | +Description: |
| 9 | +* Pregancy outcomes referred to generically as BMAS, for Births, Miscarriages, Abortions, Stillbirths |
| 10 | +* Stata program to calculate the months pregnant (P) preceding BMAS codes. |
| 11 | +* Illustrate with PKIR71FL.dta (Pakistan 2017-18 DHS) and all pregnancies in vcal_6. |
| 12 | +* Sequence them as in the table in the final report (Births, Stillbirths, Miscarriages, Abortions) |
| 13 | +* An interval is censored if it is so close to the beginning of the calendar (the early months) that |
| 14 | +* it is impossible to be sure of the number of preceding months of P's |
| 15 | +If the data are perfect, the month of conception will be the first month with a "P". However, the woman may not know when she actually became pregnant. It can happen that an abortion or miscarriage in the data is not preceded by ANY months with P. DHS would usually say that the duration of the pregnancy is one plus the number of preceding months of "P". |
| 16 | +
|
| 17 | +The pregnancy outcome variable produced is "type" and can be tabulate by covariates. |
| 18 | +This program is different from the perinatal mortality code, CM_PMR.do, found in the DHS Program Code Share Library. |
| 19 | +https://github.com/DHSProgram/DHS-Indicators-Stata/tree/master/Chap08_CM |
| 20 | +The CM_PMR.do will calculate stillbirths and live births as well as perinatal mortality but excludes miscarriage and abortions. |
| 21 | +
|
| 22 | +***************************************************************************/ |
| 23 | + |
| 24 | +* drops any saved programs. |
| 25 | +program drop _all |
| 26 | + |
| 27 | +program calc_interval_length |
| 28 | + |
| 29 | +* Construct a file with a separate record for each BMAS |
| 30 | +* We look for strings that end in B, C, A, or S and are preceded (chronologically) by P's |
| 31 | +* Allow for possible codes C, A that are not preceded by P |
| 32 | + |
| 33 | +* mbi: months as months before interview. mbi=col-v018 |
| 34 | +* cmc: months in century month codes. cmc=v017+80-col |
| 35 | + |
| 36 | +* Because there is a reshape of the data, the data should be reduced to only the variables needed. |
| 37 | +* For the program the following variables are needed: v001 v002 v003 v005 v017 v018 vcal_6 |
| 38 | + |
| 39 | +* However, if there is interest to tabulate the pregnancy outcome by specific background variables, then they should be included as well. For instance, v024, v025, v106, and v190 are included below. |
| 40 | +keep v001 v002 v003 v005 v017 v018 v024 v025 v106 v190 vcal_6 |
| 41 | + |
| 42 | +* Calculate the number of P's that immediately precede the BMAS, allowing for 0 to 11 |
| 43 | +* Index the event by col, not cmc or mbi, and allow col to go from 1 to 79 |
| 44 | + |
| 45 | +* To reduce to events and intervals that are entirely included in the 60 months before the interview, |
| 46 | +* in the loop below replace "80" with "60+v018" |
| 47 | + |
| 48 | +quietly forvalues lcol=1/80 { |
| 49 | +gen type_`lcol'=. |
| 50 | +replace type_`lcol'=1 if substr(vcal_6,`lcol',1)=="B" |
| 51 | +replace type_`lcol'=2 if substr(vcal_6,`lcol',1)=="S" |
| 52 | +replace type_`lcol'=3 if substr(vcal_6,`lcol',1)=="C" |
| 53 | +replace type_`lcol'=4 if substr(vcal_6,`lcol',1)=="A" |
| 54 | +gen interval_`lcol'= . |
| 55 | +replace interval_`lcol'= 0 if substr(vcal_6,`lcol'+1,1)~="P" & `lcol'+1<=80 |
| 56 | +replace interval_`lcol'= 1 if substr(vcal_6,`lcol'+1,1) =="P" & substr(vcal_6,`lcol'+2,1)~="P" & `lcol'+2<=80 |
| 57 | +replace interval_`lcol'= 2 if substr(vcal_6,`lcol'+1,2) =="PP" & substr(vcal_6,`lcol'+3,1)~="P" & `lcol'+3<=80 |
| 58 | +replace interval_`lcol'= 3 if substr(vcal_6,`lcol'+1,3) =="PPP" & substr(vcal_6,`lcol'+4,1)~="P" & `lcol'+4<=80 |
| 59 | +replace interval_`lcol'= 4 if substr(vcal_6,`lcol'+1,4) =="PPPP" & substr(vcal_6,`lcol'+5,1)~="P" & `lcol'+5<=80 |
| 60 | +replace interval_`lcol'= 5 if substr(vcal_6,`lcol'+1,5) =="PPPPP" & substr(vcal_6,`lcol'+6,1)~="P" & `lcol'+6<=80 |
| 61 | +replace interval_`lcol'= 6 if substr(vcal_6,`lcol'+1,6) =="PPPPPP" & substr(vcal_6,`lcol'+7,1)~="P" & `lcol'+7<=80 |
| 62 | +replace interval_`lcol'= 7 if substr(vcal_6,`lcol'+1,7) =="PPPPPPP" & substr(vcal_6,`lcol'+8,1)~="P" & `lcol'+8<=80 |
| 63 | +replace interval_`lcol'= 8 if substr(vcal_6,`lcol'+1,8) =="PPPPPPPP" & substr(vcal_6,`lcol'+9,1)~="P" & `lcol'+9<=80 |
| 64 | +replace interval_`lcol'= 9 if substr(vcal_6,`lcol'+1,9) =="PPPPPPPPP" & substr(vcal_6,`lcol'+10,1)~="P" & `lcol'+10<=80 |
| 65 | +replace interval_`lcol'=10 if substr(vcal_6,`lcol'+1,10)=="PPPPPPPPPP" & substr(vcal_6,`lcol'+11,1)~="P" & `lcol'+11<=80 |
| 66 | +replace interval_`lcol'=11 if substr(vcal_6,`lcol'+1,11)=="PPPPPPPPPPP" & substr(vcal_6,`lcol'+12,1)~="P" & `lcol'+12<=80 |
| 67 | +} |
| 68 | + |
| 69 | +reshape long type_ interval_, i(v001 v002 v003) j(col) |
| 70 | +rename *_ * |
| 71 | + |
| 72 | +drop if type==. |
| 73 | +label variable type "Type of pregnancy outcome" |
| 74 | +label define type 1 "Live birth" 2 "Stillbirth" 3 "Miscarriage" 4 "Abortion" |
| 75 | +label values type type |
| 76 | + |
| 77 | +label variable interval "Preceding months of P" |
| 78 | +replace interval=99 if interval==. |
| 79 | +label define interval 99 "Censored" |
| 80 | +label values interval interval |
| 81 | + |
| 82 | +*tab interval type |
| 83 | +*tab interval type [iweight=v005/1000000] |
| 84 | + |
| 85 | +tab type [iweight=v005/1000000] |
| 86 | + |
| 87 | +save months_pregnant.dta, replace |
| 88 | + |
| 89 | +end |
| 90 | + |
| 91 | +*************************************************************************** |
| 92 | +*************************************************************************** |
| 93 | +*************************************************************************** |
| 94 | +*************************************************************************** |
| 95 | +* Execution begins here |
| 96 | + |
| 97 | +* Specify your workspace, the data should be saved here as well unless you specify a different path for the data. |
| 98 | +* cd ... |
| 99 | + |
| 100 | +******************************** |
| 101 | +use "PKIR71FL.DTA" , clear |
| 102 | +* In this survey the BMAS are in vcal_6; C is the symbol for Miscarriage |
| 103 | +******************************** |
| 104 | + |
| 105 | +* run the program |
| 106 | +calc_interval_length |
0 commit comments