Announcement

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

  • Store numeric values into memory to use them to create new data sets

    I have been reading the Statalist for years and I am thrilled to finally join this forum and potentially interact with Nick Cox and other Stata legends who seem to know all the answers.

    I have the following data set that specifies one SGP value for a given range of values (Low Limit to High Limit)
    SGP Low Limit Gain High Limit Gain
    3 0 5
    4 6 8
    6 9 10
    From the data set above, I need to create a long dataset that looks like this:
    SGP Gain
    3 0
    3 1
    3 2
    3 3
    3 4
    3 5
    4 6
    4 7
    4 8
    6 9
    6 10
    Does anyone know how to do it?

    Thanks!

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(sgp lowlimitgain highlimitgain)
    3 0  5
    4 6  8
    6 9 10
    end
    
    gen expand = high - low + 1
    expand expand
    bysort sgp : gen gain = low[1] + _n - 1
    
    list sgp gain, sepby(sgp)
    
         +------------+
         | sgp   gain |
         |------------|
      1. |   3      0 |
      2. |   3      1 |
      3. |   3      2 |
      4. |   3      3 |
      5. |   3      4 |
      6. |   3      5 |
         |------------|
      7. |   4      6 |
      8. |   4      7 |
      9. |   4      8 |
         |------------|
     10. |   6      9 |
     11. |   6     10 |
         +------------+

    Comment


    • #3
      Nick, Thank you so much! It worked beautifully.

      Comment

      Working...
      X