Stata - Merging 2 datasets

#1
Hi all,

How can I merge Dataset1 and Dataset2 to create Dataset3? Merge m:m Group doesn't provide the result expected...

Thanks for your help.

StdDev.


Dataset1
Group Elt
A 01
A 02
A 03
B 04
B 05
C 06
C 07


Dataset2
Group Type
A CP
A CM
B CB
B TD
C CA


Dataset3
Group Elt Type
A 01 CP
A 01 CM
A 02 CP
A 02 CM
A 03 CP
A 03 CM
B 04 CB
B 04 TD
B 05 CB
B 05 TD
C 06 CA
C 07 CA
 

bukharin

RoboStataRaptor
#2
Code:
use Dataset1
joinby Group using Dataset2
If there are any Groups present in Dataset1 but not Dataset2, or vice versa, you may also want to specify the unmatched() option - see -help joinby-
 

bukharin

RoboStataRaptor
#4
No worries. -merge m:m- is a very strange beast - I have no idea why StataCorp wrote it like that. The help file even tells you not to use it, recommending -joinby- instead!! There is a user-written package called -mmerge- that you can get from SSC which is much easier to use than the official -merge- command. Internally, -mmerge- performs many-to-many matches using -joinby- - the way it should be done!