Announcement

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

  • From Long to Wide (I think)

    Hi,

    I am trying to make a single variable F1a_1 (from a repeat group) with a repetitive set of observations (Obs) 1-6 (RL1), into six new variables F1a_1_1-F1a_1_6 that are all in the same observation. I am at a lost. Thanks for the help

    Patch
    .
    Obs RL1 F1a
    1 1 28
    2 2 35
    3 3 32
    4 4 23
    5 5 34
    6 6 4
    7 1 6
    8 2 3
    9 3 3
    10 4 0
    11 5 3
    12 6 0
    13 1 55
    14 2 42
    15 3 23
    16 4 31
    17 5 3
    18 6 4
    into
    Obs F1a_1 F1a_2 F1a_3 F1a_4 F1a_5 F1a_6
    1 28 35 32 23 34 4
    2 6 3 3 0 3 0
    3 55 42 23 31 3 4

  • #2
    Code:
    clear 
    input Obs    RL1    F1a
    1    1    28
    2    2    35
    3    3    32
    4    4    23
    5    5    34
    6    6    4
    7    1    6
    8    2    3
    9    3    3
    10    4    0
    11    5    3
    12    6    0
    13    1    55
    14    2    42
    15    3    23
    16    4    31
    17    5    3
    18    6    4
    end 
    
    replace Obs = ceil(Obs/6)
    
    reshape wide F1a, i(Obs) j(RL1)
    
    list 
    
         +-----------------------------------------------+
         | Obs   F1a1   F1a2   F1a3   F1a4   F1a5   F1a6 |
         |-----------------------------------------------|
      1. |   1     28     35     32     23     34      4 |
      2. |   2      6      3      3      0      3      0 |
      3. |   3     55     42     23     31      3      4 |
         +-----------------------------------------------+
    
    .

    Comment


    • #3
      Thanks Nick.... I am not sure what I am doing work, but I am getting a "values of variable RL1 not unique within Obs" error code. Any advice. Thanks again

      Comment


      • #4
        Code:
        duplicates list Obs RL1

        Comment

        Working...
        X