clear //Enter the filepath where you have downloaded data from IPUMS PMA, I recommend this is also your R working directory cd "[enter filepath to your downloaded data from IPUMS PMA]" //Create a data file with the variables RESULTFQ, FERTPREF, FULLPANELWEIGHT, STRATA, EAID, PHASE, GEOCD, GEONG //Update the ### with the name of your data file from IPUMS PMA use pma_00###.dta //Keep only observations where the female respondent was interviewed in all three phases keep if resultfq_1 == 1 & resultfq_2 == 1 & resultfq_3 == 1 //Create new geography variable to separate DRC and Nigeria sub-national samples gen geog = country replace geog = 3 if geocd == 2 & country == 2 replace geog = 8 if geong == 2 & country == 9 label define geography 1 "Burkina Faso" 2 "Kinshasa, DRC" 3 "Kongo Central, DRC" 7 "Kenya" 8 "Lagos, Nigeria" 9 "Kano, Nigeria" label values geog geography //Revert No Response cases to missing foreach var of varlist fertpref_* { recode `var' (98/99=.) } //Revert No Response cases to missing foreach var of varlist fertpref_* { recode `var' (98/99=.) } //Generally following the 2-phase example of Zimmerman et al. 2023 label define general_category 1 "Wants a child" 2 "No more children" 3 "Don't know" forvalues i = 1(1)3 { gen gen_cat_`i' = . replace gen_cat_`i' = 1 if fertpref_`i' == 1 replace gen_cat_`i' = 2 if fertpref_`i' == 2 replace gen_cat_`i' = 3 if fertpref_`i' == 97 | fertpref_`i' == 3 label values gen_cat_`i' general_category } //alluvial figure keep country geog urban subnational eaid_* strata_* gen_cat_* fullpanelweight drop if gen_cat_1 == . drop if gen_cat_2 == . drop if gen_cat_3 == . gen seqnum = _n export delimited "alluvial_wide.csv", replace