Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: randomly drop duplicates


From   Stefan Bernhard <stefanbernhard88@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: randomly drop duplicates
Date   Fri, 31 May 2013 16:48:06 +0200

bys varnames  : gen rnd = uniform()
bys varnames (rnd) : keep if _n == 1

should do it.

You generate a random (here uniformly distributed) variable over the
duplicate condition (=varnames), sort by it and keep only the first of
the randomly sorted list.

regards
Stefan Bernhard

2013/5/31 Ann Montgomery <ann.montgomery@mail.utoronto.ca>:
> Hi,
>
> I'd like to drop duplicates randomly instead of dropping the first duplicate row. I can't find reference to this in -duplicates drop-?
>
>
> thanks, Ann
>
>
> Ann Montgomery
> PhD(c) University of Toronto
>
>
> *
> *   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index