* do e:\DHS\programs\merging\merge_successive_siblings_do_9Feb2021.txt * Program to construct pairs of children, a reference child plus next earlier sibling * This example does not include the mother's variables * It should be merged with the KR file, using cd e:\DHS\DHS_data\scratch use v001 v002 v003 b* using "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\BDBR7RFL.DTA", clear *keep v001 v002 v003 b* egen sibsize=count(bidx),by(v001 v002 v003) * construct two files, one for the younger child in a pair and one for the older child sort v001 v002 v003 bidx save temp_younger.dta, replace rename b* b*_sib * attach the child with bidx=2 to the child with bidx=1 * attach the child with bidx=3 to the child with bidx=2 * etc. gen bidx=bidx_sib-1 sort v001 v002 v003 bidx merge v001 v002 v003 bidx using temp_younger.dta tab _merge * the child with bidx=1 does not get attached to another child * the child with bidx=sibsize does not have another child attached to him/her * remove these two types of cases drop if bidx==0 | bidx_sib==. tab _merge drop _merge * reduce to the interval of the KR file keep if b19<60 keep v001 v002 v003 bidx* b0* b3* b4* b5* b11* b18* order v001 v002 v003 bidx* b0* b3* b4* b5* b11* b18* * The following formula works if the birth is not a multiple birth or is the first in a multiple * birth, i.e. if b0==0 or b0==1 gen b11_test=int((b18-b18_sib)/(365.25/12)) if b0<=1 gen delta=b11_test-b11 tab delta b0,m sort v001 v002 v003 bidx list if _n<=50, table clean * save with some filename and then merge with the KR file