Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Pavlos C. Symeou" <p.symeou@lmu.de> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Merging two datasets multiple times |
Date | Wed, 07 Apr 2010 13:01:51 +0200 |
Thanks Maarten! On 07/04/2010 11:51, Maarten buis wrote:
--- On Wed, 7/4/10, Pavlos C. Symeou wrote:I have two datasets (A and B) which I need to merge.<snip>Basically, for every patent I want to have all its IPCs and all SICs in the same row.A combination of -reshape- and -merge- may be the easiest solution here: *--------------------------- begin example ----------------------- // create some example data clear input id str4 ipc_1 str4 ipc_2 1 AAAA BBBB 2 AAAA CCCC 3 DDDD CCCC end tempfile a save `a' clear input str4 ipc str6 sic_1 str6 sic_2 str6 sic_3 AAAA zzzzz xxxxx yyyyyy BBBB tttttt rrrrrr ooooo CCCC www gggg pppp DDDD foo bar bla end tempfile b save `b' // the actual answer use `a' reshape long ipc_, i(id) j(destination) rename ipc_ ipc save `a', replace use `b' merge 1:m ipc using `a' assert _merge == 3 drop _merge rename ipc ipc_ rename sic_1 sic_1_ rename sic_2 sic_2_ rename sic_3 sic_3_ reshape wide ipc_ sic_1_ sic_2_ sic_3_, i(id) j(destination) list *--------------------- end example -------------------------- (For more on examples I sent to the Statalist see: http://www.maartenbuis.nl/example_faq ) Hope this helps, Maarten -------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- * * 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/
* * 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/