Announcement

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

  • How to calculate change from baseline in panel dataset

    I have a panel dataset organized months: Month 0, Month 6, Month 12, and Month 18. Other variables in the dataset are participant ID, group, and sbp (the outcome variable). How do I calculate a new variable representing the change from baseline for the difference between Month 0 vs. Month 6, Month 0 vs Month 12, and Month 0 vs. Month 18? A sample dataset is attached. Your help will be appreciated.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(id group time) double sbp
    1 1  0 129.5
    1 1  6 121.5
    1 1 12   120
    1 1 18   120
    2 2  0   140
    2 2  6   138
    2 2 12   136
    2 2 18   126
    3 3  0 125.8
    3 3  6 123.6
    3 3 12 120.5
    3 3 18   120
    4 4  0 118.6
    4 4  6 117.9
    4 4 12 116.9
    4 4 18 115.9
    end


  • #2
    Code:
    assert inlist(time, 0, 6, 12, 18)
    by id group (time), sort: gen byte change_from_baseline = sbp-sbp[1] if time[1] == 0
    If an individual has no baseline observation, the change_from_baseline will be set to missing value for all observations of that individual.
    Note: You have both id and group variables, and in the example data they are the same. I cannot tell whether it is the variable id or the variable group which identifies individual participants. I wrote the code with -by id group-, but if the identifier for an individual is just id, then it should be -by id-. And if the identifier for an individual is just group, then it should be -by group-.

    Comment


    • #3
      Thank you!

      Comment

      Working...
      X