Statalist


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

RE: st: ordered tabulation with only top values shown


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: ordered tabulation with only top values shown
Date   Thu, 19 Mar 2009 16:49:46 -0000

Some examples (assumes installation of -groups- and -modes-): 

. sysuse auto
(1978 Automobile Data)

. groups mpg, order(h) select(5)

  +-------------------------------+
  | mpg   Freq.   Percent    Cum. |
  |-------------------------------|
  |  18       9     12.16   12.16 |
  |  19       8     10.81   22.97 |
  |  14       6      8.11   31.08 |
  |  21       5      6.76   37.84 |
  |  22       5      6.76   44.59 |
  +-------------------------------+

. groups mpg, order(h) select(f >= 3)

  +-------------------------------+
  | mpg   Freq.   Percent    Cum. |
  |-------------------------------|
  |  18       9     12.16   12.16 |
  |  19       8     10.81   22.97 |
  |  14       6      8.11   31.08 |
  |  21       5      6.76   37.84 |
  |  22       5      6.76   44.59 |
  |-------------------------------|
  |  25       5      6.76   51.35 |
  |  16       4      5.41   56.76 |
  |  17       4      5.41   62.16 |
  |  24       4      5.41   67.57 |
  |  20       3      4.05   71.62 |
  |-------------------------------|
  |  23       3      4.05   75.68 |
  |  26       3      4.05   79.73 |
  |  28       3      4.05   83.78 |
  +-------------------------------+

. modes mpg

Mode of mpg

----------------------
Mileage   |
(mpg)     |  Frequency
----------+-----------
       18 |          9
----------------------

. modes mpg, nmodes(5)

----------------------
Mileage   |
(mpg)     |      Freq.
----------+-----------
       14 |          6
       18 |          9
       19 |          8
       21 |          5
       22 |          5
       25 |          5
----------------------

Nick 
n.j.cox@durham.ac.uk 

Nick Cox

-fre- is excellent for this and related problems. 

But there are other solutions too which have been around for some time.  

-modes- from SJ does what Rodrigo wants. So would -groups- from SSC. 

-groups- has one advantage over -modes- or -fre-: it extends to frequencies of two or more variables considered jointly. 

Nick 
n.j.cox@durham.ac.uk 

Martin Weiss

One could think of constructs with the -in- qualifier here, but Maarten`s answer is unbeatable: -ssc d fre- takes care of both ordering and subsetting the values...

Rodrigo Briceño

> Thanks Maarten and Martin. To clarify my opaque need to Martin what I
> need is that the table produced only shows the first ten values (the
> highest 10 values or any other small figure) to avoid having really
> long tables of results and further editing (erasing anything below the
> 10th greatest value). It is more clear now?
> 
> 2009/3/18 Maarten buis <maartenbuis@yahoo.co.uk>:
> >
> > --- Rodrigo Briceno wrote:
> >> I recently discovered the use of the command
> >> tab with the option sort in order to get an ordered table of
> >> frequencies (descendant order).
> >> I am wondering if I can use an additional option in order to show only
> >> some specific set of results, since some categories on my tables are
> >> really long (more than 256 categories in one case).
> >> Also I have the doubt if tab could be combined with an option in order
> >> to get ascendant frequencies.
> >
> > Yes, see -ssc describe fre- for Ben Jann's -fre- package.

*
*   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