Announcement

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

  • Tabulating the variable's highest value and show the highest frequency

    Hello all, I am having difficulty of tabulating a variable that shows the highest frequency and the highest value. Below is the best attempt to figure out this issue.


    tabsort coph_visits, sort(frequency)

    coph_visits | Freq. Percent Cum.
    ------------+-----------------------------------
    2 | 67 8.84 8.84
    1 | 61 8.05 16.89
    3 | 59 7.78 24.67
    4 | 50 6.60 31.27
    5 | 49 6.46 37.73
    7 | 47 6.20 43.93
    6 | 46 6.07 50.00
    8 | 35 4.62 54.62
    9 | 34 4.49 59.10
    13 | 34 4.49 63.59
    12 | 33 4.35 67.94
    14 | 29 3.83 71.77
    10 | 25 3.30 75.07
    16 | 25 3.30 78.36
    11 | 22 2.90 81.27
    18 | 21 2.77 84.04
    15 | 18 2.37 86.41
    19 | 15 1.98 88.39
    20 | 13 1.72 90.11
    17 | 11 1.45 91.56
    0 | 9 1.19 92.74
    21 | 9 1.19 93.93
    22 | 7 0.92 94.85
    23 | 7 0.92 95.78
    24 | 6 0.79 96.57
    25 | 5 0.66 97.23
    27 | 4 0.53 97.76
    29 | 3 0.40 98.15
    26 | 2 0.26 98.42
    28 | 2 0.26 98.68
    32 | 2 0.26 98.94
    34 | 2 0.26 99.21
    36 | 2 0.26 99.47
    33 | 1 0.13 99.60
    35 | 1 0.13 99.74
    37 | 1 0.13 99.87
    38 | 1 0.13 100.00
    ------------+-----------------------------------
    Total | 758 100.00


    I also utilized this command: gsort -coph_visits . But that would only answer a small part of this issue. Many thanks!

  • #2
    tabsort is from tab_chi on SSC, as you are asked to explain (FAQ Advice #12).

    There are many ways to do this. The simplest is to find the maximum and then
    tabulate it. (The percent shown is then vacuous.) See also extremes (also SSC).
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . su mpg
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
             mpg |         74     21.2973    5.785503         12         41
    
    . tab mpg if mpg == r(max)
    
        Mileage |
          (mpg) |      Freq.     Percent        Cum.
    ------------+-----------------------------------
             41 |          1      100.00      100.00
    ------------+-----------------------------------
          Total |          1      100.00
    
    .. extremes mpg , high
    
      +------------+
      | obs:   mpg |
      |------------|
      |  68.    31 |
      |  43.    34 |
      |  57.    35 |
      |  66.    35 |
      |  71.    41 |
      +------------+
    
    . extremes mpg , high n(1)
    
      +------------+
      | obs:   mpg |
      |------------|
      |  71.    41 |
      +------------+
    
    . extremes mpg , high n(1) freq
    
      +-------------+
      | freq:   mpg |
      |-------------|
      |     1    41 |
      +-------------+

    Comment


    • #3
      Originally posted by Nick Cox View Post
      tabsort is from tab_chi on SSC, as you are asked to explain (FAQ Advice #12).

      There are many ways to do this. The simplest is to find the maximum and then
      tabulate it. (The percent shown is then vacuous.) See also extremes (also SSC).
      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . su mpg
      
      Variable | Obs Mean Std. Dev. Min Max
      -------------+---------------------------------------------------------
      mpg | 74 21.2973 5.785503 12 41
      
      . tab mpg if mpg == r(max)
      
      Mileage |
      (mpg) | Freq. Percent Cum.
      ------------+-----------------------------------
      41 | 1 100.00 100.00
      ------------+-----------------------------------
      Total | 1 100.00
      
      .. extremes mpg , high
      
      +------------+
      | obs: mpg |
      |------------|
      | 68. 31 |
      | 43. 34 |
      | 57. 35 |
      | 66. 35 |
      | 71. 41 |
      +------------+
      
      . extremes mpg , high n(1)
      
      +------------+
      | obs: mpg |
      |------------|
      | 71. 41 |
      +------------+
      
      . extremes mpg , high n(1) freq
      
      +-------------+
      | freq: mpg |
      |-------------|
      | 1 41 |
      +-------------+
      Thank you so much! I will go ahead and configure this out.

      Comment

      Working...
      X