* do e:\DHS\programs\fertility_planning_status\fert_planning_do_10May2019.txt * Calculate fertility planning status table, 6.5, for DHS 6 and 7 surveys * Modification of a program first written for NFHS-4 log using e:\DHS\programs\fertility_planning_status\fert_planning_log, replace set more off ************************************************************ program define reduce_IR_file * check whether b19 is in the file scalar suseb19=0 capture confirm numeric variable b19_01, exact if _rc>0 { gen b19_01=. } quietly summarize b19_01 if r(mean)>0 & r(mean)<. { scalar suseb19=1 } if suseb19==0 { local li=2 while `li'<=6 { gen b19_0`li'=. local li=`li'+1 } } keep caseid v005 v008 v011 v012 bord_01-bord_06 b0_01-b0_06 b3_01-b3_06 b19_01-b19_06 m10_1-m10_6 v201 v213 v214 v225 * v213 V213 currently pregnant * v225 V225 current pregnancy wanted gen womanid=_n rename *_0* *_* save IRtemp.dta, replace end ************************************************************ program define reshape_births use IRtemp.dta, clear * construct a file of births in the past five years reshape long bord_ b0_ b3_ b19_ m10_, i(womanid) j(bidx) drop if bord==. rename *_ * * adjustment to birth order for multiple births; see Guide to DHS Statistics replace bord=bord-b0+1 if b0>1 gen interval=v008-b3 if suseb19==1 { replace interval=b19 } keep if interval<60 drop interval gen age_at_birth=-2 + int((b3-v011)/60) replace age_at_birth=1 if age_at_birth<1 label define age_at_birth 1 "<20" 2 "20-24" 3 "25-29" 4 "30-34" 5 "35-39" 6 "40-44" 7 "45-49" label values age_at_birth age_at_birth tab age_at_birth,m save IRtemp_births.dta, replace end ************************************************************ program define append_current_preg * construct a file of pregnancies use IRtemp.dta, clear keep caseid v005 v008 v011 v012 v201 v213 v214 v225 keep if v213==1 rename v225 m10 gen bidx=0 * if the woman is currently pregnant, set the birth order of the pregnancy gen bord=v201+1 tab v214,m gen preg_duration=v214 replace preg_duration=9 if v214>9 gen cmc_preg_delivery=v008+(9-preg_duration) gen age_at_birth=-2 + int((cmc_preg_delivery-v011)/60) * It can happen that a woman age 49 is pregnant and will give birth at age 50. Push any such cases into 45-49 replace age_at_birth=7 if age_at_birth>7 save IRtemp_pregs.dta, replace append using IRtemp_births.dta gen birth_order=bord replace birth_order=4 if bord>4 save IRtemp_births_plus_pregs.dta, replace end ************************************************************ program define calculate_table use IRtemp_births_plus_pregs.dta, clear tab birth_order m10 [iweight=v005/1000000], row tab age_at_birth m10 [iweight=v005/1000000], row end ************************************************************ ************************************************************ ************************************************************ ************************************************************ * EXECUTION BEGINS HERE set maxvar 10000 use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\KEIR72FL.DTA" , clear *use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\UGIR7AFL.DTA" , clear *use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\UGIR60FL.DTA" , clear *use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\PKIR71FL.DTA" , clear *use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\PKIR61FL.DTA" , clear cd e:\DHS\DHS_data\scratch reduce_IR_file reshape_births append_current_preg calculate_table