Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: How to figure out the most common value |
Date | Mon, 28 Nov 2011 09:28:42 +0000 |
In statistics the most common value is called the mode. See, for example, SJ-3-2 sg113_1 . . . . . . . . . . . . . . . . . . Software update for modes (help modes if installed) . . . . . . . . . . . . . . . . . N. J. Cox Q2/03 SJ 3(2):211 provides new option for specifying the number of modes to be shown STB-50 sg113 . . . . . . . . . . . . . . . . . . . . . . Tabulation of modes (help modes if installed) . . . . . . . . . . . . . . . . . N. J. Cox 7/99 pp.26--27; STB Reprints Vol 9, pp.180--181 provides table of most frequent observations (modes) which you would need to install from the Stata Journal website. In your case, you want to look at several variables together, which will be easier with a temporary -reshape-: preserve reshape long var , i(obs) modes var, nmodes(5) restore But you don't need -modes-: -tab, sort- will give you the same information, and more besides. In your case, these look like ICD9 codes, which you may well be holding as strings -- or at least I would advise that. -modes- is happy with string variables, but if your problem does concern string variables, it would have been better to state that, as some solutions may presume numeric variables. Nick On Mon, Nov 28, 2011 at 9:14 AM, Dudekula, Anwar <dudekulaan@upmc.edu> wrote: > I am working on a dataset with varaibles/values as shown below. > > Is there a stata code which can tell me the top 5 most common values occuring among the > all the variables (var1-var) > > > ---------------------------------------------------- > Observation var1 var2 var3 var4 var5 > ---------------------------------------------------- > Observation1 560.9 596.1 568 . 305.1 > Observation2 355.8 441.4 496 . 530.81 > Observation3 530.81 . . . > Observation4 568 530.81 . 414 > Observation5 701.9 565.1 . . > Observation6 714 . 530.81 493.9 729.1 > Observation7 564 . 305.1 789.04 . > * * 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/