Announcement

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

  • Average mean change from baseline

    I have panel data with a continuous outcome (systolic bp). The time variable ranges from (0 through 48 months). I want to create an average change in systolic bp value from the baseline. For each participant, I want to average all follow-up values and then subtract from the baseline value. I need help with writing the code.

    The title of this post should be "average change from baseline".
    Last edited by Al Bothwell; 23 Nov 2021, 13:39. Reason: wrong title

  • #2
    Hi Al, I've noticed you've made several posts here requesting help but giving the barest level of detail or description. There are several possible models that could be used to model mean systolic blood pressure, and therefore several possible answers to your question. For concrete help, is advisable to read the FAQ which asks you to provide a reproducible data example (using -dataex-), and in this case, the model you are trying to fit. The solution will likely involve -margins-, but I can't say more without further details. For example, is time modeled continuously or at discrete visits? Are there random factors to consider?

    You may find this page on repeated measures analysis from UCLA's statistical consulting instructive. You may consider analysis using -mixed- (the current name for -xtmixed-).

    Comment


    • #3
      I agree with Leonardo Guizzetti It is hard to help with your code because we can't see what it is. Nor can we see example data (systolic bp is not a legal variable name, even). Nor is average change necessarily equal to change in average, depending on definitions.

      Although in substance quite unlike your data, this example code is intended to be general enough to cope with irregular times of observation and even the presence of missing values, and so may help. At this point only you know your equivalent of invest (whatever your systolic blood pressure variable is), company (identifier) and year (time variable);


      Code:
      webuse grunfeld, clear
      
      gen ignore = missing(invest)
      bysort company (ignore year) : gen base_time = year[1]
      by company: egen base_value = mean(cond(year == base_time, invest, .))
      by company: egen later_mean = mean(cond(year != base_time, invest, .))
      
      tabdisp company, c(base_* later_mean)
      
      
      
      ----------------------------------------------
        Company |  base_time  base_value  later_mean
      ----------+-----------------------------------
              1 |       1935       317.6    623.3052
              2 |       1935       209.9    421.0316
              3 |       1935        33.1    105.9316
              4 |       1935       40.29    88.53579
              5 |       1935       39.68    62.96684
              6 |       1935       20.36    57.25579
              7 |       1935       24.43    48.81474
              8 |       1935       12.93    44.46842
              9 |       1935       26.63     42.6921
             10 |       1935        2.54    3.113158
      ----------------------------------------------

      Comment


      • #4
        Thank you, Nick. I replaced the variable names in your code and run it successfully. Next time, I will post a random percent of the actual dataset.

        Comment

        Working...
        X