Announcement

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

  • Create time variables in long-format data as set-up time-varying covariate analysis

    Hello,

    I have the following data in long-format (i.e. panel data).

    Code:
    clear
    input int idno double duration
    4 .09308692676249145
    4 .17522245037645448
    4 .28473648186173856
    4 .38329911019849416
    4 .48186173853524983
    4  .5913757700205339
    4  .8569472963723477
    5 .12594113620807665
    5   .243668720054757
    5 .32854209445585214
    5  .4353182751540041
    5   .731006160164271
    end

    and I would like to create _t0 and _t variables for time-varying cox regression analysis. Similar to the below:

    Code:
    clear
    input int idno double(duration _t0 _t)
    4 .09308692676249145                  0 .09308692676249145
    4 .17522245037645448 .09308692676249145 .17522245037645448
    4 .28473648186173856 .17522245037645448 .28473648186173856
    4 .38329911019849416 .28473648186173856 .38329911019849416
    4 .48186173853524983 .38329911019849416 .48186173853524983
    4  .5913757700205339 .48186173853524983  .5913757700205339
    4  .8569472963723477  .5913757700205339  .8569472963723477
    5 .12594113620807665                  0 .12594113620807665
    5   .243668720054757 .12594113620807665   .243668720054757
    5 .32854209445585214   .243668720054757 .32854209445585214
    5  .4353182751540041 .32854209445585214  .4353182751540041
    5   .731006160164271  .4353182751540041   .731006160164271
    end
    Any help would be much appreciated.

  • #2
    Code:
    bysort idno (duration): gen double t0 = cond(_n>1, duration[_n-1], 0)
    gen double t = duration

    Comment


    • #3
      Thank you, Øyvind !

      Comment

      Working...
      X