Announcement

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

  • Summing the values of a variable WITHOUT taking into the frequency

    Hello all,

    Following on from https://www.statalist.org/forums/for...ir-frequencies, I did the following

    Code:
    bysort f2_afr_mal: gen f2_afr_mal_freq = f2_afr_mal * _N
    This produces the following table, when using
    Code:
    tab f2_afr_mal_freq
    Code:
    f2_afr_mal_ |
           freq |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |      4,010       62.33       62.33
             28 |          1        0.02       62.35
             32 |          1        0.02       62.37
             38 |          1        0.02       62.38
             44 |          1        0.02       62.40
             49 |          1        0.02       62.41
             50 |          1        0.02       62.43
             53 |          1        0.02       62.44
             58 |          1        0.02       62.46
             60 |          1        0.02       62.47
             62 |          1        0.02       62.49
             63 |          4        0.06       62.55
             68 |          1        0.02       62.57
             69 |          1        0.02       62.58
             70 |          3        0.05       62.63
             73 |          1        0.02       62.65
             78 |          3        0.05       62.69
             80 |          3        0.05       62.74
             83 |          1        0.02       62.75
             84 |          2        0.03       62.79
             85 |          1        0.02       62.80
             86 |          2        0.03       62.83
             88 |          4        0.06       62.89
             89 |          1        0.02       62.91
             94 |          1        0.02       62.93
             96 |          2        0.03       62.96
             98 |          1        0.02       62.97
            101 |          1        0.02       62.99
            102 |          5        0.08       63.07
            104 |          2        0.03       63.10
            105 |          1        0.02       63.11
            106 |          1        0.02       63.13
            108 |          6        0.09       63.22
            112 |          2        0.03       63.25
            114 |          2        0.03       63.28
            115 |          1        0.02       63.30
            117 |          3        0.05       63.35
            119 |          1        0.02       63.36
            128 |          2        0.03       63.39
            130 |         10        0.16       63.55
            135 |          5        0.08       63.63
            137 |          1        0.02       63.64
            138 |          3        0.05       63.69
            141 |          4        0.06       63.75
            144 |          5        0.08       63.83
            155 |          5        0.08       63.90
            160 |          8        0.12       64.03
            161 |          8        0.12       64.15
            162 |          3        0.05       64.20
            176 |          1        0.02       64.22
            177 |          3        0.05       64.26
            200 |          8        0.12       64.39
            203 |          7        0.11       64.50
            204 |          1        0.02       64.51
            208 |         13        0.20       64.71
            210 |         22        0.34       65.06
            216 |          3        0.05       65.10
            220 |          2        0.03       65.13
            221 |         13        0.20       65.33
            226 |          2        0.03       65.37
            228 |         19        0.30       65.66
            230 |         23        0.36       66.02
            240 |         10        0.16       66.17
            241 |          1        0.02       66.19
            264 |          1        0.02       66.21
            266 |         14        0.22       66.42
            267 |          1        0.02       66.44
            280 |         55        0.85       67.29
            286 |         26        0.40       67.70
            291 |          1        0.02       67.71
            297 |         33        0.51       68.23
            300 |          1        0.02       68.24
            303 |          1        0.02       68.26
            336 |         48        0.75       69.00
            362 |          2        0.03       69.03
            405 |         81        1.26       70.29
            426 |         71        1.10       71.40
            442 |          1        0.02       71.41
            500 |        125        1.94       73.36
            576 |        192        2.98       76.34
            598 |          1        0.02       76.36
            812 |        406        6.31       82.67
            960 |          1        0.02       82.68
           1110 |      1,110       17.25       99.94
           1176 |          1        0.02       99.95
           1221 |          1        0.02       99.97
           2009 |          1        0.02       99.98
           3015 |          1        0.02      100.00
    ------------+-----------------------------------
          Total |      6,433      100.00
    Now I would like to add up just the numbers in the very first column (0, 28, 32 etc) without taking into the frequencies. When I use display r(sum) after using the sum command, the total is taking into the frequencies but I don't want that, as I have already take that into account.
    Last edited by Chris Rooney; 19 Apr 2022, 03:57.

  • #2
    This is hard for me to follow but perhaps

    Code:
    egen tag = tag(f2_afr_mal)
    su f2_afr_mal if tag
    is what you seek.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      This is hard for me to follow but perhaps

      Code:
      egen tag = tag(f2_afr_mal)
      su f2_afr_mal if tag
      is what you seek.
      Great thanks. This works!

      Comment

      Working...
      X