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]

Re: st: Merging two datasets multiple times


From   Robert Picard <[email protected]>
To   [email protected]
Subject   Re: st: Merging two datasets multiple times
Date   Wed, 7 Apr 2010 12:08:06 -0400

Pavlos,

Here's one way to do it that avoids using -reshape-:


*--------------------------- begin example -----------------------

version 11
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

sort ipc
by ipc: assert _n == 1 // make sure that ipc is unique!
tempfile b
save `b'

local nipc 2
local nsic 3
use "`a'", clear

forvalues i = 1/`nipc' {
    rename ipc_`i' ipc
    sort ipc
    merge m:1 ipc using "`b'", keep(master match) nogen
    rename ipc ipc_`i'
    forvalues j = 1/`nsic' {
        rename sic_`j' sic_`j'_`i'
    }
}
list
*--------------------- end example --------------------------



On Wed, Apr 7, 2010 at 7:01 AM, Pavlos C. Symeou <[email protected]> wrote:
> 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:
*
*   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