Hello,
I would like to merge the following two data sets (data set A and B) where each row is uniquely identified by id1 and id2 both in each data set (no duplicates). The merge is done by variables id1 and id2 but with some additional condition:
if id2 is not missing in data set B, then merge by two varaibles id1 and id2 both;
if id2 is missing in data set B, then merge by id1 only (i.e., when there are multiple rows in data set A, one row in B is merged to multiple rows in A, such as id1=4)
The issue is the missing values for id2 in data set B.
I wondered if you have any clean way to do this merge? What I can come up is to do the merge in a few steps, like merge non missing id2 first and merge missing id2 at the second step. Thank you for your time!
Mandy1
*************Data set A************
id1 id2 wage
1 101 1000
2 302 2000
2 305 3000
3 400 5000
4 500 5000
4 502 6000
*************Data set B************
id1 id2 hours
1 . 40
2 302 20
2 305 40
3 400 35
4 . 40
*************desired resulted data set************
id1 id2 wage hours
1 101 1000 40
2 302 2000 20
2 305 3000 40
3 400 5000 35
4 500 5000 40
4 502 6000 40
... View more