****************************************************************************** program define wanted_fertility * Subprogram goes into the main Stata program for fertility rates, Chapter 5 of final report * Written by Tom Pullum, this version September 2024 * Note: for "wanted" fertility, the "keep" statement must include b5_*, b6_*, b7_*, and v613 *v613 byte %8.0g V613 ideal number of children * Loop through the birth history * Assume that v613 has never changed from the beginning of childbearing to the present * Classify a birth as unwanted if, when the pregnancy occurred, the number of living children was >=v613 * Need to calculate the number of living children that the woman had at the beginning of every pregnancy. * Work backwards from bidx=1 * The coding does not use current pregnancy status in any way * It is possible that the last child was not wanted, but died, and now the woman has her desired number; * survival status of the last child is not used * The coding is only relevant if v613=v613 keep v001 v002 v003 v005 v008 v011 b3_* b5_* b6_* b7_* v613 awfact* $gcovars * Initialize and construct cmc of death for children who died local li=1 while `li'<=20 { gen nlc_`li'=0 gen cmc_of_death_`li'=. replace cmc_of_death_`li'=b3_`li'+b7_`li' if int(b6_`li'/100)<3 replace cmc_of_death_`li'=b3_`li'+b7_`li'+6 if int(b6_`li'/100)==3 local li=`li'+1 } local li=1 while `li'<=19 { local lii=`li'+1 while `lii'<=20 { replace nlc_`li'= nlc_`li'+1 if (b5_`lii'==0 & cmc_of_death_`lii'>=b3_`li'-9) | b5_`lii'==1 local lii=`lii'+1 } ***UPPER LIMIT USED IN JORDAN 2012 AND SOME OTHER SURVEYS *gen wanted_`li'=1 if nlc_`li'