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
R Zhang <[email protected]>
To
[email protected]
Subject
Re: st: merge with random assignment
Date
Fri, 21 Mar 2014 16:20:53 -0400
Thank you very much !!!
On Fri, Mar 21, 2014 at 5:46 AM, Phil Schumm <[email protected]> wrote:
> 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/
*
* 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/