Announcement

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

  • Reshaping from wide to long

    Hello, I'm rather new to Stata. I'm having an issue reshaping my data from wide to long. This is what my data currently looks like:

    subject condai condap condpi condpp
    1 0.6 0.4 0.2 0.1
    2 0.3 0.7 0.2 0.4
    3 0.2 0.7 0.2 0.1

    I would like it to look like this:

    subject cond value
    1 ai 0.6
    1 ap 0.4
    1 pi 0.2
    1 pp 0.1
    2 ai 0.3
    2 ap 0.7
    2 pi 0.2
    2 pp 0.4
    3 ai 0.2
    3 ap 0.7
    1 pi 0.2
    1 pp 0.1

    This is the code I've been attempting:

    Code:
    . reshape long cond i(subject) j(cond)
    This is the error Stata returns:

    Code:
    option i() required
    
             long                                wide
            +---------------+                   +------------------+
            | i   j   a   b |                   | i   a1 a2  b1 b2 |
            |---------------| <--- reshape ---> |------------------|
            | 1   1   1   2 |                   | 1   1   3   2  4 |
            | 1   2   3   4 |                   | 2   5   7   6  8 |
            | 2   1   5   6 |                   +------------------+
            | 2   2   7   8 |
            +---------------+
    
            long to wide: reshape wide a b, i(i) j(j)    (j existing variable)
            wide to long: reshape long a b, i(i) j(j)    (j    new   variable)
    Hopefully you can help! Thanks.

    Jacob

  • #2
    Firstly, add a comma in your code to separate the i() option, secondly use the -string- option.
    Code:
    reshape long cond, i(subject) j(newvar) string

    Comment


    • #3
      Thank you!

      Comment

      Working...
      X