capture prog drop this prog def this local obs1 `1' local i 1 while `i'<=`obs1' { local match=0 parse "$hold",parse(" ") while `match'==0 & "`1'"~="" { use _junk2,clear rename $guy $guy2 sort `*' save ${temploc}__junk,replace use ${temploc}_junk1 keep if $guy==`i' sort `*' merge `*' using ${temploc}__junk count if _merge==3 if _result(1)>0 { keep if _merge==3 local dup2=$guy2[1] local match 1 } mac shift } if `match'==0 { use ${temploc}_junk2,clear local dup2=$guy[1] } use ${temploc}_junk,clear sort $group merge $group using ${temploc}_fam keep if _merge==3 &((year==$yr1 & $guy==`i')|(year==$yr2 & $guy==`dup2')) drop _merge assert _N==2 sort year append using ${temploc}dummy save ${temploc}dummy,replace use ${temploc}_junk sort $group merge $group using ${temploc}_fam drop if _merge==3 &((year==$yr1 & $guy==`i')|(year==$yr2 & $guy==`dup2')) drop _merge save ${temploc}_junk,replace use ${temploc}_junk2 drop if $guy==`dup2' save ${temploc}_junk2,replace local i=`i'+1 } end this `1' exit 0