Announcement

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

  • How to multiply the number of observation and frequency??

    I have a dataset as


    position | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 1,174 91.93 91.93
    1 | 72 5.64 97.57
    2 | 13 1.02 98.59
    3 | 1 0.08 98.67
    4 | 1 0.08 98.75
    6 | 3 0.23 98.98
    8 | 2 0.16 99.14
    9 | 3 0.23 99.37
    11 | 2 0.16 99.53
    12 | 1 0.08 99.61
    16 | 1 0.08 99.69
    24 | 1 0.08 99.77
    45 | 1 0.08 99.84
    47 | 1 0.08 99.92
    64 | 1 0.08 100.00
    ------------+-----------------------------------
    Total | 1,277 100.00

    I want to multiply the "position" with "frequency". How to do it? I uses the chat gpt and other forum as well but couldn't get the answer. please help me out.

  • #2
    Do you want a new variable (column) in your dataset or do you want a new column in the table you posted?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Either way works for me. But i would prefer a new variable.

      Comment


      • #4
        Code:
        . // create a copy of your data
        . clear
        
        . input position freq
        
              position       freq
          1. 0  1174
          2. 1  72
          3. 2  13
          4. 3  1
          5. 4  1
          6. 6  3
          7. 8  2
          8. 9  3
          9. 11  2
         10. 12  1
         11. 16  1
         12. 24  1
         13. 45  1
         14. 47  1
         15. 64  1
         16. end
        
        . expand freq
        (1,262 observations created)
        
        . drop freq
        
        .
        . // generate the variable you wanted
        . bysort position : gen wanted = _N*position
        
        .
        . // admire the result:
        . list in 1/5
        
             +-------------------+
             | position   wanted |
             |-------------------|
          1. |        0        0 |
          2. |        0        0 |
          3. |        0        0 |
          4. |        0        0 |
          5. |        0        0 |
             +-------------------+
        
        . list in -11/l, sepby(position)
        
              +-------------------+
              | position   wanted |
              |-------------------|
        1267. |        9       27 |
        1268. |        9       27 |
        1269. |        9       27 |
              |-------------------|
        1270. |       11       22 |
        1271. |       11       22 |
              |-------------------|
        1272. |       12       12 |
              |-------------------|
        1273. |       16       16 |
              |-------------------|
        1274. |       24       24 |
              |-------------------|
        1275. |       45       45 |
              |-------------------|
        1276. |       47       47 |
              |-------------------|
        1277. |       64       64 |
              +-------------------+
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment

        Working...
        X