Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: -groups- updated on SSC [was: ... tabulate the reversed data]


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: -groups- updated on SSC [was: ... tabulate the reversed data]
Date   Wed, 26 Jan 2011 13:30:59 +0000

James Keeler (a.k.a. Calchas) asked about tabulating in reverse. 

I now have updated my -groups- to do this. -groups- is a tabulation routine. -groups- shows groups for any number of variables, at the price of ravelling them into a single vector. In some people's jargon, it can used to look for covariate classes, for example. 

An early write-up of -groups- was included in 

SJ-3-4  pr0011  . . . . . . . .  Speaking Stata: Problems with tables, Part II
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/03   SJ 3(4):420--439                                 (no commands)
        reviews three user-written commands (tabcount, makematrix,
        and groups) as different approaches to tabulation problems

Thanks to Kit Baum, the new version is now available on SSC. Stata 8 is required. To install or update, use -ssc- (or -adoupdate- as appropriate). 

Here is how -groups- works: 

. sysuse auto 

. groups rep78

  +----------------------------------+
  | rep78   Freq.   Percent     Cum. |
  |----------------------------------|
  |     1       2      2.90     2.90 |
  |     2       8     11.59    14.49 |
  |     3      30     43.48    57.97 |
  |     4      18     26.09    84.06 |
  |     5      11     15.94   100.00 |
  +----------------------------------+

A new -reverse- option just reverses what would have otherwise have been shown. 

. groups rep78, reverse

  +----------------------------------+
  | rep78   Freq.   Percent     Cum. |
  |----------------------------------|
  |     5      11     15.94   100.00 |
  |     4      18     26.09    84.06 |
  |     3      30     43.48    57.97 |
  |     2       8     11.59    14.49 |
  |     1       2      2.90     2.90 |
  +----------------------------------+

There is a little language for tweaking what is shown. Cumulatives are especially 
tricky: do you want <, <=, >, >= ? 

. groups rep78, reverse show(f p RP) ge

  +----------------------------------+
  | rep78   Freq.   Percent     Cum. |
  |----------------------------------|
  |     5      11     15.94    15.94 |
  |     4      18     26.09    42.03 |
  |     3      30     43.48    85.51 |
  |     2       8     11.59    97.10 |
  |     1       2      2.90   100.00 |
  +----------------------------------+

-list- options tweak the cosmetics. 

. groups rep78 foreign, reverse sepby(rep78)

  +------------------------------------+
  | rep78    foreign   Freq.   Percent |
  |------------------------------------|
  |     5    Foreign       9     13.04 |
  |     5   Domestic       2      2.90 |
  |------------------------------------|
  |     4    Foreign       9     13.04 |
  |     4   Domestic       9     13.04 |
  |------------------------------------|
  |     3    Foreign       3      4.35 |
  |     3   Domestic      27     39.13 |
  |------------------------------------|
  |     2   Domestic       8     11.59 |
  |------------------------------------|
  |     1   Domestic       2      2.90 |
  +------------------------------------+

My guess is that the -reverse- option is mostly useful for Univariate tabulations.

Nick 
[email protected] 

Nick Cox
========

Phil Ender's -rtab- does this. Use -findit rtab- to find it. 

(I was surprised that more things don't (seem to). But one nice solution is fine!) 

keeler james
============

I wonder if anyone can help. For data tabulation of a field in a dataset you can use the command 'tab mk' to list the frequency table as folows. What if we want to do a 'tab' for reversed mk, i.e. starting the largest number first to the smallest number last? In this case it is 112, 109, 106.7, ..., 22, 15.3 1nd 6.7? many thanks.

calchas


. tab mk

 Assessment |
       mark |      Freq.     Percent        Cum.
------------+-----------------------------------
        6.7 |          1        0.09        0.09
       15.3 |          1        0.09        0.18
         22 |          1        0.09        0.27

[...] 

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index