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   Ann Montgomery <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: randomly drop duplicates
Date   Fri, 31 May 2013 15:23:12 +0000

great thanks, it worked

Ann
________________________________________
From: [email protected] [[email protected]] on behalf of Stefan Bernhard [[email protected]]
Sent: Friday, May 31, 2013 10:48 AM
To: statalist
Subject: Re: st: randomly drop duplicates

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/



*
*   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