* do e:\DHS\programs\fert_planning_do_20Mar2018.txt * Calculate fertility planning status table, 6.5, for Nepal 2016 DHS * Includes a check of whether b19 is present log using e:\DHS\programs\fert_planning_log_20Mar2018, replace set more off set maxvar 10000 ************************************************************ program define reduce_IR_file use IRtemp.dta, clear capture confirm numeric variable b19_01, exact if _rc>0 { gen b19_01=v008-b3_01 gen b19_02=v008-b3_02 gen b19_03=v008-b3_03 gen b19_04=v008-b3_04 gen b19_05=v008-b3_05 gen b19_06=v008-b3_06 } keep caseid v005 v008 v011 bord_01-bord_06 b0_01-b0_06 b3_01-b3_06 b19_01-b19_06 m10_1-m10_6 v201 v213 v214 v225 * m10 V225 current pregnancy wanted * v213 V213 currently pregnant * v214 V214 duration of current pregnancy * 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 b3==. rename *_ * gen 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 gen birth_order=bord tab birth_order,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 v201 v213 v214 v225 keep if v213==1 rename v225 m10 gen bidx=0 * set the birth order of the pregnancy for a woman who is currently pregnant gen birth_order=v201+1 tab birth_order,m tab v214,m gen preg_duration=v214 * Note: there may be women who report themselves in the 10th month of pregnancy. * Such women SHOULD BE grouped with the 9th month. However, in order to match * the reports, we must skip that step, in effect saying that the child WILL BE * born THE MONTH BEFORE the interview!! The following line would further shift to 8. * replace preg_duration=8 if v214>=9 & v214<. * Also there may be women for whom duration of current pregnancy is missing, in which * case the woman's age at birth is not calculated or estimated and the total of the number * of births under "mother's age at birth" may be short gen cmc_delivery=v008+(9-preg_duration) gen age_at_birth=-2 + int((cmc_delivery-v011)/60) save IRtemp_pregs.dta, replace append using IRtemp_births.dta tab birth_order replace birth_order=4 if birth_order>4 tab birth_order 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 use e:\DHS\DHS_data\IR_files\NPIR7HFL.dta, clear *use e:\DHS\DHS_data\IR_files\GHIR70FL.dta, clear cd e:\DHS\DHS_data\scratch save IRtemp.dta, replace reduce_IR_file reshape_births append_current_preg calculate_table