Announcement

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

  • creating subsets within one unit

    Hi, I have a dataset that records a total number of 'fatalities' (a variable that has values from 1 to 130) per each 'event'. Events are all unique. However, I need to create 'rows' (observations) that will be as many for each event as the number of 'fatalities'. E.g., if there are 10 fatalities for one event, I need 10 lines of entry for that event. All of the values will be the same across all variables with one event but only my new variable should look like an order list (vertically, 1 2 3 4 5 6 7 8 9 10).

    I would appreciate any guidance!

  • #2
    Welcome to Statalist.

    Perhaps this example will guide you to the result you want.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(event fatalities)
    101 3
    102 5
    end
    expand fatalities
    by event, sort: generate seq = _n
    list, sepby(event)
    Code:
    . list, sepby(event)
    
         +------------------------+
         | event   fatali~s   seq |
         |------------------------|
      1. |   101          3     1 |
      2. |   101          3     2 |
      3. |   101          3     3 |
         |------------------------|
      4. |   102          5     1 |
      5. |   102          5     2 |
      6. |   102          5     3 |
      7. |   102          5     4 |
      8. |   102          5     5 |
         +------------------------+

    Comment

    Working...
    X