I have a dataset from a cross-sectional survey, and I want to merge it with a second dataset that identifies sibling pairs. In the sibling dataset, the IDs are stored in two variables: aid_1 and aid_2. However, in the cross-sectional dataset, the IDs are stored in a single variable named aid. The issue arises when, for example, an individual like '21316754' appears in the aid_2 variable but not in aid_1. As a result, when I merge the two datasets, this individual is not matched because the merge only looks at the aid_1 variable. I would like to ensure that all individuals, whether they appear in aid_1 or aid_2, are matched in the merged dataset with the cross-sectional data. Is there a way to merge using both aid_1 and aid_2 onto the aid variable from the cross-sectional dataset?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str8(aid_1 aid_2) double famid "11316754" "21316754" 3354 "14614574" "24614574" 3508 "26710363" "26710369" 1122 "17608172" "27608172" 1194 "57118376" "57165233" 2391 "17175746" "57175746" 2161 "57165632" "57196170" 1889 "17196641" "57196641" 1695 "57110111" "57199978" 2297 "17206302" "57206302" 2028 "57149272" "57235039" 1937 "17253432" "57253432" 3406 "17254985" "57254985" 2519 "57245546" "57255146" 2008 "88221444" "88249047" 3506 "90315394" "90315399" 2305 "10316654" "90316654" 2147 "10316952" "90316952" 1569 "90500031" "90500037" 3735 "90500380" "90500381" 2156 "90500550" "90500553" 2793 "90500854" "90500859" 1184 "20503705" "90503705" 1886 "90504240" "90504243" 3479 "90504700" "90504701" 1761 "90504822" "90504827" 3754 "90504901" "90504907" 1140 "57139316" "90506100" 2253 "90506192" "90506195" 2085 "90506292" "90506297" 3372 "10506342" "90506342" 1045 "90506395" "90506396" 1245 "90506396" "90506398" 1245 "90506395" "90506398" 1245 "90506480" "90506483" 1358 "90506595" "90506598" 1952 "90506795" "90506796" 1627 "90506792" "90506797" 1781 "90506933" "90506939" 1355 "90508073" "90508079" 2515 "90508130" "90508131" 1493 "90508172" "90508177" 2486 "90508220" "90508229" 2863 "90508973" "90508979" 1280 "90540752" "90540753" 1471 "20540757" "90540757" 1519 "90544200" "90544202" 1046 "90570023" "90570029" 1659 "90570286" "90570288" 2046 "90570470" "90570471" 1895 "90570684" "90570689" 1179 "10570810" "90570810" 3326 "90571211" "90571217" 2527 "16711861" "90571567" 2425 "90571801" "90571807" 2913 "90572065" "90572068" 3251 "90572070" "90572071" 2224 "90572221" "90572227" 3677 "90572063" "90572268" 1420 "90572383" "90572389" 2961 "90572390" "90572393" 1615 "90572920" "90572925" 2814 "90573136" "90573138" 3323 "90573396" "90573398" 3383 "90573616" "90573618" 2320 "90573896" "90573898" 3352 "90573943" "90573944" 1522 "90573944" "90573949" 1522 "90573943" "90573949" 1522 "90573952" "90573955" 1466 "90573956" "90573958" 1421 "90573954" "90573959" 2012 "20574505" "90574505" 2230 "90574532" "90574538" 2753 "20574622" "90574622" 2943 "90574652" "90574657" 1737 "90574823" "90574829" 2973 "90575002" "90575005" 3684 "90575114" "90575119" 1105 "90575201" "90575207" 3313 "90575242" "90575247" 1425 "90575325" "90575328" 2634 "90575334" "90575339" 1686 "90575621" "90575624" 3416 "90575825" "90575827" 1488 "90575902" "90575905" 2798 "90575936" "90575938" 3582 "90576142" "90576145" 2041 "90576246" "90576248" 3110 "90576326" "90576327" 1568 "30576392" "90576392" 2373 "30576392" "90576395" 2373 "90576392" "90576395" 2373 "90576392" "90576398" 2373 "30576392" "90576398" 2373 "90576395" "90576398" 2373 "90576760" "90576761" 3526 "90576832" "90576837" 2710 "90576893" "90576897" 1246 "90576896" "90576898" 2273 end
Comment