Announcement

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

  • reshape form long to wide

    Good morning,
    I am trying to trasform a db from long to wide, but by typing that command :
    Code:
    reshape wide StartDate Status Progress Duration__in_seconds_ Finished RecordedDate ResponseId  Q33 Q34 Q35 Q36 Q36_11_TEXT Q65_1 Q65_2 Q65_3 Q65_4 Q65_5 Q65_6 Q65_7 mathexperience_1 mathexperience_2 mathexperience_3 mathexperience_4 mathexperience_5 mathexperience_6 mathexperience_7 mathexperience_8 mathexperience_9 mathexperience_10  Q67_1 Q67_2 Q67_3 Q67_4 Q67_5 Q67_6 Q67_7 Q68_1 Q68_2 Q68_3 Q68_4 Q68_5 Q68_6 Q68_7 tomorrowsecurity_1 Q70 Q70_4_TEXT Q71 Q71_4_TEXT ideaFUTURO_1 ideaFUTURO_2 ideaFUTURO_3 ideaFUTURO_4 ideaFUTURO_5 ideaFUTURO_6 ideaFUTURO_7 ideaFUTURO_8 ideaFUTURO_9 ideaFUTURO_10 ideaFUTURO_11 ideaFUTURO_12 ideaFUTURO_13 ideaFUTURO_14 ideaFUTURO_15 Q73_1 Q73_2 Q73_3 Q73_4 Q73_5 Q73_6 Q73_7 Q73_8 Q73_9 Q73_10 Q73_11 Q73_12 Q74_1 Q74_2 Q74_3 Q74_4 Q74_5 Q74_6 Q74_7 Q74_8 Q74_9 Q74_10 Q75_1 Q75_2 Q75_3 idid dscore StuID1 StuID2 StuID3 StuID3N StuIDoverall DAYstring DAYdate Hstring Hdate TIMEstart, i(IDpanel) j(Time)
    I receive that message:
    Code:
    variable mathexperience_10 already defined
    and typing reshape error I get that reply:

    Code:
    reshape error 
    (j = 0 1)
    Time is unique within IDpanel and
    all the "reshape xi" variables are constant within Time;
    there is no error with which "reshape error" can help.

    What i did wrong? I am really no Idea!
    Thank you so muc for your time
    Last edited by Chiara Tasselli; 22 Mar 2022, 08:21.

  • #2
    My guess is that, amount the possible values of "Time" there is "0" in it. So, when Stata tries to joint "mathexperience_1" with the time index "0", it creates "mathexperience_10", which clashes with a pre-existing variable with the same name. The same will also happy to ideaFUTURO, it just has not gone there yet. I'd suggest perhaps recoding your "Time" into a new string variable like A, B, C, or _0, _1, _2 etc. and that should solve it.

    And also, please carefully evaluate if a wide data is actually needed. Wide data this wide are very difficult to analyze. Most of the statistical analyses work better with long data. And if you just need data from one cycle at a time, using "if" or "bysort" to loop through a long data will be a lot easier.
    Last edited by Ken Chui; 22 Mar 2022, 08:39.

    Comment


    • #3
      Many thanks for your reply, yes actually I solved the problem by simply changing some variable's names (because once solved for that variable, problem arise for others) ! Thank you so much for your help .

      Thank you also for the suggestion about wide data (I only need it for some operation of data cleaning and rearranging dataset as actually is a panel but with variables fixed in time)

      Comment

      Working...
      X