Announcement

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

  • assessing change in outcomes at different time points

    Hi there,

    I would like to assess changes in outcomes (PHQ-4 scores) from baseline to last observation, baseline to 3 months, and baseline to 6 months, where individuals in the dataset report these measures at different timepoints.

    I used the following code to calculate the change from baseline to last observation. How can I adapt this to calculate the change from baseline to 3 months and baseline to 6 months, if possible? Thank you very much for your help, much appreciated.

    gen missingPHQ4_crfl = missing(PHQ4_cr)
    bysort missingPHQ4_crfl pid (date) : gen change_PHQ4_crfl = PHQ4_cr[_N] - PHQ4_cr[1]
    bysort pid (change_PHQ4_crfl) : replace change_PHQ4_crfl = change_PHQ4_crfl[1]

    su change_PHQ4_crfl


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid float(date PHQ4_cr)
    2640739 23362  8
    2601672 23712  4
    2783799 23559  8
    2369902 23658  3
    2589963 23491 10
    2597833 23569  6
    1897982 23163  5
    2369941 23042  2
    2796273 23931  0
    2788566 23630  9
    2608931 23313  2
    2934668 23848  4
    2807186 23607  7
    2684888 23653 10
    2711011 23479  4
    2831792 23656  4
    2523708 23408  3
    2515519 23109  3
    2589089 23284  8
    2428397 23628  4
    2792814 23924  6
    2432081 22993  7
    2489312 23088 12
    2524164 23184  0
    2524168 23217  3
    2137023 22980  9
    2817119 23622  6
    2200501 23307  9
    2671054 23712 10
    2785280 23560  5
    2509050 23116  5
    2793044 23573  4
    2660809 23401  1
    2863740 23716  1
    2726795 23594  2
    2855672 23698  5
    2383006 23541  7
    2789558 23568  7
    2167655 23209  8
    2876408 23798  4
    2655408 23389  8
    2828400 23644 12
    2588133 23269 10
    2870328 23747  2
    2669539 23611  8
    2936921 23857  4
    2638962 23628  7
    2610403 23311 10
    2311386 23565  4
    2675651 23499  7
    end
    format %td date

  • #2
    Hi there,
    Just checking in to see if anyone has thoughts on the best way to handle this.
    Thank you so much for your support — I really appreciate it.

    Many thanks,
    Karen

    Comment


    • #3
      Karen:
      the first issue with your example is that no -pid- has repeated measures of -PHQ4_cr-:
      Code:
      . tab pid
      
              pid |      Freq.     Percent        Cum.
      ------------+-----------------------------------
          1897982 |          1        2.00        2.00
          2137023 |          1        2.00        4.00
          2167655 |          1        2.00        6.00
          2200501 |          1        2.00        8.00
          2311386 |          1        2.00       10.00
          2369902 |          1        2.00       12.00
          2369941 |          1        2.00       14.00
          2383006 |          1        2.00       16.00
          2428397 |          1        2.00       18.00
          2432081 |          1        2.00       20.00
          2489312 |          1        2.00       22.00
          2509050 |          1        2.00       24.00
          2515519 |          1        2.00       26.00
          2523708 |          1        2.00       28.00
          2524164 |          1        2.00       30.00
          2524168 |          1        2.00       32.00
          2588133 |          1        2.00       34.00
          2589089 |          1        2.00       36.00
          2589963 |          1        2.00       38.00
          2597833 |          1        2.00       40.00
          2601672 |          1        2.00       42.00
          2608931 |          1        2.00       44.00
          2610403 |          1        2.00       46.00
          2638962 |          1        2.00       48.00
          2640739 |          1        2.00       50.00
          2655408 |          1        2.00       52.00
          2660809 |          1        2.00       54.00
          2669539 |          1        2.00       56.00
          2671054 |          1        2.00       58.00
          2675651 |          1        2.00       60.00
          2684888 |          1        2.00       62.00
          2711011 |          1        2.00       64.00
          2726795 |          1        2.00       66.00
          2783799 |          1        2.00       68.00
          2785280 |          1        2.00       70.00
          2788566 |          1        2.00       72.00
          2789558 |          1        2.00       74.00
          2792814 |          1        2.00       76.00
          2793044 |          1        2.00       78.00
          2796273 |          1        2.00       80.00
          2807186 |          1        2.00       82.00
          2817119 |          1        2.00       84.00
          2828400 |          1        2.00       86.00
          2831792 |          1        2.00       88.00
          2855672 |          1        2.00       90.00
          2863740 |          1        2.00       92.00
          2870328 |          1        2.00       94.00
          2876408 |          1        2.00       96.00
          2934668 |          1        2.00       98.00
          2936921 |          1        2.00      100.00
      ------------+-----------------------------------
            Total |         50      100.00
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Hi Carlo,
        Thanks for pointing that out, totally missed that. I've updated the data snippet below:

        ----------------------- copy starting from the next line -----------------------
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input long pid float(date PHQ4_cr)
              1 22985  6
              1 23000  7
              1 23057  8
              1 23133  3
              1 23150  6
              1 23293  6
              1 23650  9
              1 23838  8
            125 23027  5
            125 23039  5
            125 23042  5
            669 23121  2
            669 23141  0
            669 23186  1
           3138 23016  8
           3138 23099  5
           3138 23168  6
           3138 23246  5
           3138 23259  4
           3138 23365  4
           3138 23496  5
         501902 23834  7
         501902 23928  8
        1274732 23496  3
        1274732 23505  2
        1274732 23509  4
        1370594 23459  5
        1370594 23892  8
        1370594 23895 12
        1396203 23219  5
        1396203 23299  5
        1396203 23351  2
        1396203 23354  5
        1396203 23428  7
        1396203 23497  3
        1396203 23568  8
        1396203 23628  5
        1396203 23729  9
        1396203 23730  4
        1396203 23730  8
        1396203 23764  4
        1412302 23482  7
        1412302 23496  2
        1430977 23159  5
        1430977 23205  3
        1430977 23338  6
        1430977 23446  5
        1431012 23050  7
        1431012 23205  5
        1431012 23387  4
        1431012 23851  6
        1543520 23071  9
        1543520 23082  5
        1543520 23105  4
        1543520 23115  4
        1555791 23523 12
        1555791 23790 11
        1555791 23791 11
        1557999 23033  9
        1557999 23152  1
        1557999 23159  3
        1557999 23196  2
        1558052 23664  4
        1558052 23902  4
        1572325 23146  4
        1572325 23188  8
        1655998 23068  1
        1655998 23307  1
        1662217 23105  1
        1662217 23152  2
        1662217 23383  4
        1662217 23483  2
        1662217 23491  4
        1662217 23504  4
        1662217 23517  3
        1662217 23547  3
        1662217 23582  3
        1662217 23588  4
        1662217 23638  3
        1663329 23027  6
        1663329 23070  9
        1663329 23446  5
        1663920 23477  4
        1663920 23507  2
        1663920 23521  4
        1675714 23194  5
        1675714 23365  4
        1682729 23722 12
        1682729 23729  8
        1682729 23751 10
        1682729 23765  6
        1682729 23781  5
        1682729 23910 12
        1684953 23217  5
        1684953 23217  4
        1684962 23182  1
        1684962 23191  0
        1684962 23208  0
        1689438 23036 12
        1689438 23097  0
        end
        format %td date
        Many thanks
        Karen

        Comment


        • #5
          Originally posted by Karen Arulsamy View Post
          I would like to assess changes in outcomes (PHQ-4 scores) from baseline to last observation, baseline to 3 months, and baseline to 6 months, where individuals in the dataset report these measures at different timepoints.
          You can do something like that shown below. (I've omitted displaying your data snippet and shortened the unwieldy outcome variable name.)

          The main point is that you'll need to define acceptance windows for the observation intervals. In the code below, I've used a one-month window for the three-month time point and a two-month window for the six-month time point, but you can choose whatever is customary for your field. You can also get fancy with leap years and the like—see the help file for the function used.
          Code:
          version 19
          
          clear *
          
          quietly input long pid float(date PHQ4_cr)
          <data snippet redacted for clarity>
          end
          
          format date %tdCY-N-D
          rename PHQ4_cr sco
          
          * Change in PHQ-4 score from first observation to last
          drop if missing(sco)
          bysort pid (date): generate byte dla = sco[_N] - sco[1] if date[_N] > date[1]
          
          * Change from first to three months with one-month window (± ½ month)
          by pid: generate byte d3m = sco - sco[1] if inrange(datediff_frac(date[1], date, "m"), 2.5, 3.5)
          
          * Change from first to six months with two-month window (± 1 month)
          by pid: generate byte d6m = sco - sco[1] if inrange(datediff_frac(date[1], date, "m"), 5, 7)
          
          summarize d??
          
          exit

          Comment


          • #6
            Karen:
            a more trivial approach than the one suggested by Joseph (that I share) is the following one:
            Code:
            bysort pid ( date ): g wanted= PHQ4_cr-PHQ4_cr[1]
            It gives you back the difference between the pid-specific baseline and each consequent measurement of -PHQ4_cr-.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Thanks so much Joseph, this is super helpful. Is there an iteration I could use with Stata 15?

              Comment


              • #8
                Thanks so much Carlo Lazzaro! In the data, participants can respond at any time, so the 3-, 6-, and 12-month timelines differ by PID. Is there a way to identify which changes correspond to each timepoint using this method?

                Comment


                • #9
                  Karen:
                  typing:
                  Code:
                  . bysort pid ( date ): g elaspsed_days_from_baseline= date-date[1]
                  reveals that -PHQ4_cr- is measured at different points in time for each -pid-.
                  Therefore, while the answer to your question is, unfortunately, no, your second best is to reason in terms of waves instead of 3,6,12 months.
                  Obviously, the issue is that you're not dealing with a panel data set in technical terms, as your measurements are not repeated at equally spaced time intervals for all the -pid-.
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    Originally posted by Karen Arulsamy View Post
                    Is there an iteration I could use with Stata 15?
                    I've seen approaches like the following used in clinical studies where protocols specify windows for follow-up visits.
                    Code:
                    by pid: generate byte d3m = sco - sco[1] if inrange(date - date[1], 75, 105)
                    by pid: generate byte d6m = sco - sco[1] if inrange(date - date[1], 150, 210)
                    Out-of-window visits and missed visits are flagged analogously. (Unscheduled visits are typically for-cause and are recorded that way.)

                    Your data snippet didn't have any such case and so I didn't mention it, but using this general approach with your full dataset you might encounter the case where more than one observation falls within your chosen three- or -six-month window for a study participant. If so, then you'll need to make a decision what to do about it. There are various options—use an average or median of all within the window, select the value closest to the center of the window (and hope that there aren't ties in that regard)—and I guess depending upon your study's objective you could also consider selecting the best-case (or worst-case) change, too.

                    Comment

                    Working...
                    X