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: merge with random assignment


From   Phil Schumm <[email protected]>
To   Statalist Statalist <[email protected]>
Subject   Re: st: merge with random assignment
Date   Fri, 21 Mar 2014 04:46:55 -0500

On Mar 20, 2014, at 10:41 PM, R Zhang <[email protected]> wrote:
> I need to merge two tables

<snip>

> I want to merge two tables using ionumber. The goal is to add naics to talbe 2. As you can tell, sometimes ionumber in table 1 correspond to multiple naics values. In such cases, I would like to randomly assign the ionumber to one of the 4 possible naics (11113, 11119, 11114, 11116).


    use table1
    isid ionumber naics, so
    set seed <random_number_seed>
    gen u = runiform()
    isid ionumber u, so
    by ionumber: keep if _n==1
    merge 1:m ionumber using table2

Specifying <random_number_seed> ensures that the selection is reproducible.


-- Phil


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index