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 at the end of May, 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   Ann Montgomery <ann.montgomery@mail.utoronto.ca>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: randomly drop duplicates
Date   Fri, 31 May 2013 15:23:12 +0000

great thanks, it worked

Ann
________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Stefan Bernhard [stefanbernhard88@gmail.com]
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 <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/



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