Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: merging dataset...


From   daniel klein <klein.daniel.81@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: merging dataset...
Date   Fri, 25 Nov 2011 12:02:08 +0100

"The quesition is how can I merge the two datasets in a mapping fashion..."

And the answer is right in the help file for -merge-, which states:

"Many-to-one merge on specified key variables

        merge m:1 varlist using filename [, options]

One-to-many merge on specified key variables

        merge 1:m varlist using filename [, options]"

[...]

"merge can perform match merges (one-to-one, one-to-many, many-to-one,
and many-to-many), which are often called 'joins' by database people."

[...]

    Setup
        . webuse overlap1, clear
        . list, sepby(id)
        . webuse overlap2
        . list

    Perform m:1 match merge, illustrating update option
        . webuse overlap1
        . merge m:1 id using
http://www.stata-press.com/data/r12/overlap2, update
        . list

    -----------------------------------------------------------------------------------------
    Perform m:1 match merge, illustrating update replace option
        . webuse overlap1, clear
        . merge m:1 id using
http://www.stata-press.com/data/r12/overlap2, update replace
        . list

    -----------------------------------------------------------------------------------------
    Perform 1:m match merge, illustrating update replace option
        . webuse overlap2, clear
        . merge 1:m id using
http://www.stata-press.com/data/r12/overlap1, update replace
        . list

and which you are supposed to read carefully _before_ posting to to
the list (http://www.stata.com/support/faqs/res/statalist.html#before).

If your problem is somehow beyond the scope of the help file or if you
are having trouble understanding (parts of) the help file you need to
make it more clear, which you are also asked to do
(http://www.stata.com/support/faqs/res/statalist.html#question).

Concerning merges you should also read
http://blog.stata.com/2011/04/18/merging-data-part-1-merges-gone-bad/

Best
Daniel
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index