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" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von gjhxmu@sina.com
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index