Announcement

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

  • Reshaping Wide Format Dataset to Long Format in Stata for BMI Z-Score Trajectories

    Hello everyone,
    I currently have a dataset in wide format where each row represents a unique subject and each column represents a different time point. Specifically, I have variables named bmiz3m, bmiz6m, bmiz9m, bmiz12m, bmiz15m, and bmiz24m representing the BMI z-score at 3, 6, 9, 12, 15, and 24 months respectively. I also have variables named inc_3, inc_6, inc_9, inc_12, inc_15, and inc_24 where inc_x is equal to 1 at x months and 0 otherwise. (No other timepoint variable in the dataset).

    I would like to reshape this dataset into long format, where I have one row for each subject-time point combination. In this long format, I would like to have a bmiz variable that represents the BMI z-score and a timepoint variable (using inc variable) that indicates the time point. My intent is to create BMI Trajectories for intervention and control group in my RCT.
    Could you please guide me on how to perform this transformation in Stata?

    Thank you in advance for your help.

  • #2
    Code:
    gen long subject_id=_n
    rename bmiz*m bmiz*
    reshape long bmiz inc_, i(subject_id) j(month)

    Comment


    • #3
      Andrew Musau Thank you very much.

      Comment

      Working...
      X