Statalist


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

st: RE: Dropping subset of observations


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Dropping subset of observations
Date   Mon, 17 Nov 2008 18:43:32 -0000

foreach day in FRI THUR WED TUE { 
	egen howmanybetter = total(frequency != "`day'"), by(id)  
	drop if howmanybetter >= 3 & frequency == "`day'"
	drop howmanybetter 
} 

In words, start with FRI and count how many observations there are for
the other days of the week for each id. If there are 3 or more, you can
drop the FRIs. 

Repeat with THUR, WED, TUE. 

You don't say how you will decide if you have 4 or more days that are
SAT, SUN, MON. 

Nick 
[email protected] 

Rijo John

 Can someone help me to figure out how to drop observations from the
data based on following criteria.

Data sample.


clear
input byte id byte value  str6 frequency
1  25        MON
1  22        SUN
1  30        WED
1  28        SAT
2  24        TUE
2  35        SAT
2  50        SUN
2  26        FRI
3  30       MON
3  28      SUN
3  35       SAT
4  50      MON
4  38      WED
4  30      SUN
5  25      MON
5  23      TUE
5  24      SUN


end

list

For each ID variable I have values for different days in a week. I
want to keep only the values associated with Sunday, Saturday and
Monday. If Monday is not available I like to keep the weekday that is
closer to monday in the order mon, tue, wed, thu, fri. Saturday and
Sunday are not available for all IDs. Similarly the number of
frequencies (SUN, MON, TUE etc..) associated with the IDs might be
different for each IDs. Can someone help me figure out how to drop
these observations. Eventually I want to retain only a maximum of
three observations with each IDs. One weekday, SUN, and SAT (if
available)


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index