Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: a question about merge

From   Philip Ryan <>
Subject   Re: st: a question about merge
Date   Fri, 03 Sep 2004 09:24:25 +0930

I think you are attempting a many:many relational join.  Try:

use file1
joinby ID using file2, unmatched(both)

This assumes that both files are sorted on ID.


At 04:16 PM 2/09/2004 -0700, you wrote:
Dear Stata support,

I have a question on merging two datasets.

Assume that I have two datasets as followings:

Master dataset is named "file1" and contains two variables:
    ID    var1
    A      1
    A      2
    B      3

The using dataset is named "file2: and also contains two variables:

   ID   var2
   A     4
   A     5
   A     6

I would like to merge these two files. I expect to get a new file
(file3) as followings:

  ID   var1  var2
  A      1    4
  A      1    5
  A      1    6
  A      2    4
  A      2    5
  A      2    6
  B      3    .

However, after I sort both datasets by ID and then type command:

        merge ID using file2.dta

The resulted file is not what I expected.

I was wondering why this happens? Can I use merge command to obtain the
file3? Thanks a lot,


Jian Zhang
*   For searches and help try:
Philip Ryan
Associate Professor,
Department of Public Health
Associate Dean (Information Technology)
Faculty of Health Sciences
University of Adelaide 5005
South Australia
tel 61 8 8303 3570
fax 61 8 8223 4075
CRICOS Provider Number 00123M
This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
copyright. If you are not the intended recipient please
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index