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

st: a question about merge


From   Jian Zhang <jzh@ucdavis.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: a question about merge
Date   Thu, 2 Sep 2004 16:16:11 -0700 (PDT)

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,

Sincerely,

Jian Zhang
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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