Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tabulating joint frequencies of M>=2 discrete outcomes

    Does anyone have a favorite way of tabulating joint frequencies for M>=2 discrete (numeric) outcomes? I've written a program tabjoint to do this (https://uwmadison.box.com/s/r4fdwda8...a99ibd6ybyicbz) that produces the output that appears below.

    But I'm wondering if others have more found more efficient ways to undertake and report such tabulations. There's nothing profound about the calculations themselves; I'm mostly curious about how others might have handled this.
    Code:
    sysuse auto
    tabjoint foreign rep78 turn, sort
    Code:
      Joint distribution of: foreign rep78 turn
    
      Joint Outcome |      Freq.     Percent        Cum.
    ----------------+-----------------------------------
       0   3   43   |          7       10.14       10.14
       0   3   40   |          4        5.80       15.94
       0   3   42   |          4        5.80       21.74
       1   5   36   |          4        5.80       27.54
       0   2   46   |          3        4.35       31.88
       0   4   43   |          3        4.35       36.23
       1   4   34   |          3        4.35       40.58
       0   2   41   |          2        2.90       43.48
       0   3   41   |          2        2.90       46.38
       0   3   44   |          2        2.90       49.28
       0   3   45   |          2        2.90       52.17
       0   4   42   |          2        2.90       55.07
       1   3   36   |          2        2.90       57.97
       1   4   35   |          2        2.90       60.87
       1   4   36   |          2        2.90       63.77
       1   5   35   |          2        2.90       66.67
       1   5   37   |          2        2.90       69.57
       0   1   40   |          1        1.45       71.01
       0   1   42   |          1        1.45       72.46
       0   2   40   |          1        1.45       73.91
       0   2   43   |          1        1.45       75.36
       0   2   44   |          1        1.45       76.81
       0   3   31   |          1        1.45       78.26
       0   3   34   |          1        1.45       79.71
       0   3   36   |          1        1.45       81.16
       0   3   37   |          1        1.45       82.61
       0   3   48   |          1        1.45       84.06
       0   3   51   |          1        1.45       85.51
       0   4   33   |          1        1.45       86.96
       0   4   39   |          1        1.45       88.41
       0   4   45   |          1        1.45       89.86
       0   4   48   |          1        1.45       91.30
       0   5   35   |          1        1.45       92.75
       0   5   37   |          1        1.45       94.20
       1   3   34   |          1        1.45       95.65
       1   4   33   |          1        1.45       97.10
       1   4   38   |          1        1.45       98.55
       1   5   32   |          1        1.45      100.00
    ----------------+-----------------------------------
              Total |         69      100.00

  • #2
    groups now maintained through the Stata Journal has been around for a while (2003) with a major rewrite a few years ago. For a quick overview, skim

    https://www.statalist.org/forums/for...updated-on-ssc

    and for a formal write-up

    SJ-18-1 st0496_1 . . . . . . . . . . . . . . . . . Software update for groups
    (help groups if installed) . . . . . . . . . . . . . . . . N. J. Cox
    Q1/18 SJ 18(1):291
    groups exited with an error message if weights were specified;
    this has been corrected

    SJ-17-3 st0496 . . . . . Speaking Stata: Tables as lists: The groups command
    (help groups if installed) . . . . . . . . . . . . . . . . N. J. Cox
    Q3/17 SJ 17(3):760--773
    presents command for listing group frequencies and percents and
    cumulations thereof; for various subsetting and ordering by
    frequencies, percents, and so on; for reordering of columns;
    and for saving tabulated data to new datasets

    Example:


    Code:
    . sysuse auto, clear 
    (1978 automobile data)
    
    . 
    . groups foreign rep78 turn, order(high) sep(0)
    
      +-------------------------------------------+
      |  foreign   rep78   turn   Freq.   Percent |
      |-------------------------------------------|
      | Domestic       3     43       7     10.14 |
      | Domestic       3     40       4      5.80 |
      | Domestic       3     42       4      5.80 |
      |  Foreign       5     36       4      5.80 |
      | Domestic       2     46       3      4.35 |
      | Domestic       4     43       3      4.35 |
      |  Foreign       4     34       3      4.35 |
      | Domestic       2     41       2      2.90 |
      | Domestic       3     41       2      2.90 |
      | Domestic       3     44       2      2.90 |
      | Domestic       3     45       2      2.90 |
      | Domestic       4     42       2      2.90 |
      |  Foreign       3     36       2      2.90 |
      |  Foreign       4     35       2      2.90 |
      |  Foreign       4     36       2      2.90 |
      |  Foreign       5     35       2      2.90 |
      |  Foreign       5     37       2      2.90 |
      | Domestic       1     40       1      1.45 |
      | Domestic       1     42       1      1.45 |
      | Domestic       2     40       1      1.45 |
      | Domestic       2     43       1      1.45 |
      | Domestic       2     44       1      1.45 |
      | Domestic       3     31       1      1.45 |
      | Domestic       3     34       1      1.45 |
      | Domestic       3     36       1      1.45 |
      | Domestic       3     37       1      1.45 |
      | Domestic       3     48       1      1.45 |
      | Domestic       3     51       1      1.45 |
      | Domestic       4     33       1      1.45 |
      | Domestic       4     39       1      1.45 |
      | Domestic       4     45       1      1.45 |
      | Domestic       4     48       1      1.45 |
      | Domestic       5     35       1      1.45 |
      | Domestic       5     37       1      1.45 |
      |  Foreign       3     34       1      1.45 |
      |  Foreign       4     33       1      1.45 |
      |  Foreign       4     38       1      1.45 |
      |  Foreign       5     32       1      1.45 |
      +-------------------------------------------+

    Comment


    • #3
      Code:
      sysuse auto, clear
      egen totab= group(foreign rep78 turn), label
      tab totab, sort
      Res.:

      Code:
      . tab totab, sort
      
      group(foreign |
        rep78 turn) |      Freq.     Percent        Cum.
      --------------+-----------------------------------
      Domestic 3 43 |          7       10.14       10.14
      Domestic 3 40 |          4        5.80       15.94
      Domestic 3 42 |          4        5.80       21.74
       Foreign 5 36 |          4        5.80       27.54
      Domestic 2 46 |          3        4.35       31.88
      Domestic 4 43 |          3        4.35       36.23
       Foreign 4 34 |          3        4.35       40.58
      Domestic 2 41 |          2        2.90       43.48
      Domestic 3 41 |          2        2.90       46.38
      Domestic 3 44 |          2        2.90       49.28
      Domestic 3 45 |          2        2.90       52.17
      Domestic 4 42 |          2        2.90       55.07
       Foreign 3 36 |          2        2.90       57.97
       Foreign 4 35 |          2        2.90       60.87
       Foreign 4 36 |          2        2.90       63.77
       Foreign 5 35 |          2        2.90       66.67
       Foreign 5 37 |          2        2.90       69.57
      Domestic 1 40 |          1        1.45       71.01
      Domestic 1 42 |          1        1.45       72.46
      Domestic 2 40 |          1        1.45       73.91
      Domestic 2 43 |          1        1.45       75.36
      Domestic 2 44 |          1        1.45       76.81
      Domestic 3 31 |          1        1.45       78.26
      Domestic 3 34 |          1        1.45       79.71
      Domestic 3 36 |          1        1.45       81.16
      Domestic 3 37 |          1        1.45       82.61
      Domestic 3 48 |          1        1.45       84.06
      Domestic 3 51 |          1        1.45       85.51
      Domestic 4 33 |          1        1.45       86.96
      Domestic 4 39 |          1        1.45       88.41
      Domestic 4 45 |          1        1.45       89.86
      Domestic 4 48 |          1        1.45       91.30
      Domestic 5 35 |          1        1.45       92.75
      Domestic 5 37 |          1        1.45       94.20
       Foreign 3 34 |          1        1.45       95.65
       Foreign 4 33 |          1        1.45       97.10
       Foreign 4 38 |          1        1.45       98.55
       Foreign 5 32 |          1        1.45      100.00
      --------------+-----------------------------------
              Total |         69      100.00
      
      .

      Comment


      • #4
        Thanks Nick and Andrew.

        Comment

        Working...
        X