Announcement

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

  • Reshape command is not working properly

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float uid double(primaryactibvity Starttime_ Stoptime_ duration)
    1  8 . . .
    1 11 . . .
    1 10 . . .
    1  5 . . .
    1  1 . . .
    1  3 . . .
    1 16 . . .
    1  . . . .
    1  . . . .
    end
    label values primaryactibvity primaryactibvity16
    label def primaryactibvity16 1 "Collecting or managing water", modify
    label def primaryactibvity16 3 "Household chores", modify
    label def primaryactibvity16 5 "Market activities", modify
    label def primaryactibvity16 8 "Cooking/Meal preparation", modify
    label def primaryactibvity16 10 "Official Meetings", modify
    label def primaryactibvity16 11 "Bathing", modify
    label def primaryactibvity16 16 "Sleeping", modify
    Hi Stata people ,

    I am reshaping wide variables to long. However, after running the command reshape long primaryactibvity Starttime_ Stoptime_ duration, i(uid) j(activity_number), I don't see all the correct values of Starttime_, Stoptime_, and duration. For example, the respondent with uid1 performs seven activities, but I see none after reshaping. Moreover, I see an activity for uid 2, although this respondent didn't perform any activities. Please see the attached image for reference. Any help is much appreciated.
    Click image for larger version

Name:	reshape.PNG
Views:	2
Size:	12.3 KB
ID:	1748227

    Attached Files

  • #2
    Attaching more observations in case it helps.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float uid double(primaryactibvity Starttime_ Stoptime_ duration)
    1  8        .        .                 .
    1 11        .        .                 .
    1 10        .        .                 .
    1  5        .        .                 .
    1  1        .        .                 .
    1  3        .        .                 .
    1 16        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    1  .        .        .                 .
    2  . 25200000 75600000                14
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    2  .        .        .                 .
    3  3 36000000 65100000 8.083333333333334
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    3  .        .        .                 .
    4  3 24300000 34200000              2.75
    4  5 32400000 36000000                 1
    4 19 37800000 48600000                 3
    4  1 54000000 64800000                 3
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    4  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    5  .        .        .                 .
    6  1        .        .                 .
    6  3        .        .                 .
    6 11        .        .                 .
    6  8        .        .                 .
    6 17        .        .                 .
    6 19        .        .                 .
    6  9        .        .                 .
    6 16        .        .                 .
    6  .        .        .                 .
    6  .        .        .                 .
    6  .        .        .                 .
    6  .        .        .                 .
    6  .        .        .                 .
    6  .        .        .                 .
    6  .        .        .                 .
    6  .        .        .                 .
    7  3        .        .                 .
    7  8        .        .                 .
    7  6        .        .                 .
    7  7        .        .                 .
    end
    label values primaryactibvity primaryactibvity16
    label def primaryactibvity16 1 "Collecting or managing water", modify
    label def primaryactibvity16 3 "Household chores", modify
    label def primaryactibvity16 5 "Market activities", modify
    label def primaryactibvity16 6 "Farming activities", modify
    label def primaryactibvity16 7 "Livestock rearing", modify
    label def primaryactibvity16 8 "Cooking/Meal preparation", modify
    label def primaryactibvity16 9 "Socializing", modify
    label def primaryactibvity16 10 "Official Meetings", modify
    label def primaryactibvity16 11 "Bathing", modify
    label def primaryactibvity16 16 "Sleeping", modify
    label def primaryactibvity16 17 "Listening Radio or Watching TV", modify
    label def primaryactibvity16 19 "Other work outside the home", modify

    Comment


    • #3
      I can only make sense of your question by taking the data example to be the result of running

      Code:
      reshape long primaryactibvity Starttime_ Stoptime_ duration, i(uid) j(activity_number)
      as your data example followed by that reshape command won't execute.

      The result may not be quite what you want yet, but I see no evidence that reshape is not working. At worst, reshape is filling in with cross-combinations that aren't of interest.
      Last edited by Nick Cox; 29 Mar 2024, 06:20.

      Comment

      Working...
      X