Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: re: Mergeing datasets


From   Christopher Baum <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: re: Mergeing datasets
Date   Tue, 26 Apr 2011 18:33:51 -0400

<>
Thomas said

     master   id1   id2   id3   id4
        106   708   673     .   676
        110   713   696     .   704
        122   721   721     .     .
        123   749   722     .   728
        129   789   789   734     .
        134   739   739     .     .
        144   800   752     .   763
        145   808   753     .   780
        151   797   764     .   781
        158   811   771     .   779

 I have a working dataset containg id.  The id may come from id1, id2, 
 id3, or id4 above:

 . list id in 1/10, clean noobs

       id
     2014
     2030
     2038
     2041
     2042
     2054
     2055
     2058
     2061
     2065

 I need to merge(?) the two so that I can get the master id for each id, 
 regardless of whether they came from id1 id2 id3 id4.
 I thought this was a job for merge, but did not find a mention for this 
 type of situations in the manual.  I suppose I could do four sequential 
 merges.  Any suggestion on how to best proceed?


reshape long id, i(master) j(newid)

will make each observation into four observations, which may then be merged with the other file. The first example you show above
does not seem to have any four-digit IDs, so I'm not sure just what variable you're trying to match, but if the notion is to match any of the id1,2,3,4 with 
the same value in another file, this should do it; you can then just 

keep if _merge==3

to retain only those records which yielded a match.

Kit Baum   |   Boston College Economics and DIW Berlin   |   http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming   |   http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata   |   http://www.stata-press.com/books/imeus.html


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index