Announcement

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

  • How to reshape data

    id coef1 coef2
    12 0 0
    13 -1.042248 -3.044248
    14 -1.871952 -1.841952
    20 .0909167 .0509167
    31 -2.090903 -2.090903
    32 0 0
    33 .1800388 .1900388
    41 -1.951823 -6.951823
    42 -1.656629 -1.956629
    43 -.0201779 -.0201779
    49 -2.234017 6.234017
    51 -1.862709 -4.862709
    54 -0.435543 1.435543

    Can I reshape the above data in the following format? Please guide me.

    order coef12 coef13 coef14 coef20 coef31 coef32 coef33 ------------- coef54
    1 0 -1.042248
    2 0 -3.044248

  • #2
    Code:
    clear
    input float(id coef1 coef2)
    12 0 0
    13 -1.042248 -3.044248
    14 -1.871952 -1.841952
    20 .0909167 .0509167
    31 -2.090903 -2.090903
    32 0 0
    33 .1800388 .1900388
    41 -1.951823 -6.951823
    42 -1.656629 -1.956629
    43 -.0201779 -.0201779
    49 -2.234017 6.234017
    51 -1.862709 -4.862709
    54 -0.435543 1.435543
    end
    
    reshape long coef, i(id) j(which)
    reshape wide coef, i(which) j(id)
    Res.:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte which float(coef12 coef13 coef14 coef20 coef31 coef32 coef33 coef41 coef42 coef43 coef49 coef51 coef54)
    1 0 -1.042248 -1.871952 .0909167 -2.090903 0 .1800388 -1.951823 -1.656629 -.0201779 -2.234017 -1.862709 -.435543
    2 0 -3.044248 -1.841952 .0509167 -2.090903 0 .1900388 -6.951823 -1.956629 -.0201779  6.234017 -4.862709 1.435543
    end

    Comment


    • #3
      Thank you so much, prof. Andrew. I got it.

      Comment

      Working...
      X