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: randomly drop duplicates


From   Stefan Bernhard <[email protected]>
To   statalist <[email protected]>
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 <[email protected]>:
> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index