capture prog drop that prog def that local obs2 `1' local i 1 while `i'<=`obs2' { local match 0 parse "$hold",parse(" ") while `match'==0 & "`1'"~="" { use ${temploc}_junk1,clear rename $guy $guy1 sort `*' save ${temploc}__junk,replace use ${temploc}_junk2 keep if $guy==`i' sort `*' merge `*' using ${temploc}__junk count if _merge==3 if _result(1)>0 { keep if _merge==3 local dup1=$guy1[1] local match 1 } mac shift } if `match'==0 { use ${temploc}_junk1,clear local dup1=$guy[1] } use ${temploc}_junk,clear sort $group merge $group using ${temploc}_fam keep if _merge==3 &((year==$yr1 & $guy==`dup1')|(year==$yr2 & $guy==`i')) 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==`dup1')|(year==$yr2 & $guy==`i')) drop _merge save ${temploc}_junk,replace use ${temploc}_junk1 drop if $guy==`dup1' save ${temploc}_junk1,replace local i=`i'+1 } end that `1' exit 0