Statalist


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

AW: RE: st: AW: Create a flag variable for 10 most frequent values


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: RE: st: AW: Create a flag variable for 10 most frequent values
Date   Tue, 17 Nov 2009 15:32:42 +0100

<> 

As discussed last night between me and Sergiy: You want the whole dataset
with all variables intact plus one that denotes membership in the "club of
most frequent values of mpg"...



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von [email protected]
Gesendet: Dienstag, 17. November 2009 15:28
An: statalist
Betreff: Re: RE: st: AW: Create a flag variable for 10 most frequent values

Suppose we need to flag the 5 most frequent values, how about the following
typings?

sysuse auto, clear
keep mpg
bys mpg: egen mycount=count(mpg)
bys mycount: g num=_n
gsort num -mycount
g tag=_n<=5
bys mycount: egen rank5=max(tag)


Hope it helps!

Rose



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