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

Re: st: Dropping min of two consecutive observations

From   Jeph Herrin <>
Subject   Re: st: Dropping min of two consecutive observations
Date   Thu, 13 Nov 2008 16:42:50 -0500

. bys ID (month) : keep if _n==_N

should do it.

Rijo John 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

*   For searches and help try:

*   For searches and help try:

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