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]

SV: st: how to drop duplicate values


From   Malin Lundberg Rasmussen <Malin.Lundberg.Rasmussen@ouh.regionsyddanmark.dk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   SV: st: how to drop duplicate values
Date   Fri, 14 Sep 2012 14:16:15 +0200

Thank you for your reply, Maarten.  
Is it possible to make 'the keeping' random? So that it will not always be the left or right eye that is kept?
/Malin

-----Oprindelig meddelelse-----
Fra: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] På vegne af Maarten Buis
Sendt: 14. september 2012 14:02
Til: statalist@hsphsun2.harvard.edu
Emne: Re: st: how to drop duplicate values

On Fri, Sep 14, 2012 at 1:53 PM, Malin Lundberg Rasmussen wrote:
> I have a cohort of patients with a severity grade for each eye. I am only going to use one eye, and I want it to be the eye with a certain grade, say 2.
> I have made the variable long, so the data looks like this:
>
> 1. id:1 var*:2
> 2. Id:1 var*:2
> 3. Id:2 var*:2
> 4.Id2: var*:3
>
> I use the command
>                              Keep if var*==2
> But then I have some patients who have the same grade in both eyes.
>
> 1. id:1 var*:2
> 2. Id:1 var*:2
> 3. Id:2 var*:2
>
> How do I drop these? (in the above list 1 or 2).

bys id: keep if _n == 1  // keep first

or

bys id : keep if _n == _N // keep last

-- Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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