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

From |
"Alan Neustadtl" <alan.neustadtl@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Dropping min of two consecutive observations |

Date |
Thu, 13 Nov 2008 16:42:48 -0500 |

If you sort the data by id and then by month I think your code will work. Look at the following example based on your data: ***** Stata Example Begin ***** clear input byte id byte value byte month 1 25 12 1 22 8 2 30 9 3 28 8 3 24 6 end list sort id month list drop if id==id[_n-1] list ***** Stata Example End ***** Best, Alan On Thu, Nov 13, 2008 at 4:33 PM, Rijo John <rmjohn@gmail.com> wrote: > Dear Statalist, > > I have some repeated observations that I need to drop. I have defined > a unique ID variable. There are two other variables "value" and > "month" for these IDs. > > Example data. > > ID Value month > 1 25 12 > 1 22 8 > 2 30 9 > 3 28 8 > 3 24 6 > > > Only few IDs are repeated in the actual data. > > Basically I need to retain only one value per ID. If I do "drop if > ID==ID[_n-1]" after sorting the IDs it could drop any of the values. > But I want the data to retain those values where in month takes the > highest value when I am dropping ID==ID[_n-1]. Something like > > drop min(month, month[_n-1]) if ID==ID[_n-1] is what I am looking for. > However, I cant use such time series operators with min function. Any > thoughts? > > Regards, > Rijo. > * > * 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/

**References**:**st: Dropping min of two consecutive observations***From:*"Rijo John" <rmjohn@gmail.com>

- Prev by Date:
**Re: st: Dropping min of two consecutive observations** - Next by Date:
**st: resend** - Previous by thread:
**Re: st: Dropping min of two consecutive observations** - Next by thread:
**st: RE: Dropping min of two consecutive observations** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |