![]() |
From | gjhxmu@sina.com |
To | statalist<statalist@hsphsun2.harvard.edu> |
Subject | Re: RE: st: AW: Create a flag variable for 10 most frequent values |
Date | Tue, 17 Nov 2009 22:27:45 +0800 |
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/
© Copyright 1996–2025 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |