Announcement

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

  • Better stset code for exit

    Hello all,

    I needed a better way to code an exit at 1200 days in Stata 18 (and convert it to months). Below is a (public) dataset with id os status (1=dead) and ostime in days. I did three lines of code but feel there has to be an easier way with an expression in the exit and/or failure option, but can't figure out a parsimonious way to do it. Would love any input.

    What I did:
    Code:
    replace os = cond(ostime>=1200 & os==1, 0, os)
    replace ostime = cond(ostime>1200, 1200, ostime)
    stset ostime, fail(os)
    The TCGA dataset below:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str15 sample byte os int ostime
    "TCGA-UT-A97Y-01" 1  144
    "TCGA-LK-A4O0-01" 1  185
    "TCGA-TS-A7P8-01" 1  457
    "TCGA-3U-A98D-01" 1  142
    "TCGA-3H-AB3T-01" 1  414
    "TCGA-MQ-A6BL-01" 1  333
    "TCGA-TS-A8AS-01" 1  795
    "TCGA-SC-A6LN-01" 1  414
    "TCGA-LK-A4NZ-01" 1  244
    "TCGA-UT-A88E-01" 1  434
    "TCGA-MQ-A6BN-01" 1  757
    "TCGA-SC-A6LR-01" 0 1168
    "TCGA-UT-A88G-01" 1   76
    "TCGA-3U-A98F-01" 1  536
    "TCGA-3U-A98E-01" 0 1916
    "TCGA-UD-AAC1-01" 1  789
    "TCGA-NQ-A57I-01" 1   20
    "TCGA-3U-A98G-01" 1  630
    "TCGA-3H-AB3U-01" 1  826
    "TCGA-ZN-A9VU-01" 0  977
    "TCGA-LK-A4O4-01" 1  949
    "TCGA-3H-AB3S-01" 1  385
    "TCGA-TS-A8AF-01" 1  358
    "TCGA-LK-A4O5-01" 1  387
    "TCGA-3U-A98I-01" 1  860
    "TCGA-ZN-A9VV-01" 0 1309
    "TCGA-SH-A7BD-01" 1  459
    "TCGA-MQ-A4LP-01" 1  527
    "TCGA-MQ-A4LM-01" 1  158
    "TCGA-ZN-A9VS-01" 0 1228
    "TCGA-TS-A7OZ-01" 1  844
    "TCGA-UD-AAC6-01" 1  456
    "TCGA-SH-A9CT-01" 1  449
    "TCGA-LK-A4O6-01" 1  448
    "TCGA-LK-A4NY-01" 1  168
    "TCGA-YS-AA4M-01" 1   84
    "TCGA-UD-AAC5-01" 1  253
    "TCGA-SH-A7BC-01" 1  727
    "TCGA-NQ-A638-01" 0    0
    "TCGA-UT-A88D-01" 1  823
    "TCGA-SH-A7BH-01" 1  243
    "TCGA-UD-AAC4-01" 1  719
    "TCGA-SC-A6LM-01" 1  881
    "TCGA-LK-A4O7-01" 1  350
    "TCGA-3H-AB3K-01" 1 1715
    "TCGA-MQ-A4LV-01" 1  107
    "TCGA-TS-A7PB-01" 1  982
    "TCGA-3H-AB3X-01" 0 1490
    "TCGA-TS-A7OY-01" 1  255
    "TCGA-UT-A88C-01" 1  863
    "TCGA-TS-A7P7-01" 1  591
    "TCGA-ZN-A9VW-01" 1   84
    "TCGA-ZN-A9VQ-01" 0  499
    "TCGA-TS-A7P6-01" 1  283
    "TCGA-SC-A6LQ-01" 1  297
    "TCGA-MQ-A4LI-01" 1  572
    "TCGA-SH-A9CU-01" 1  732
    "TCGA-LK-A4NW-01" 1  546
    "TCGA-XT-AASU-01" 1  142
    "TCGA-3H-AB3L-01" 1  361
    "TCGA-TS-A8AI-01" 1  328
    "TCGA-3H-AB3O-01" 1 1302
    "TCGA-SC-A6LP-01" 1   78
    "TCGA-MQ-A6BQ-01" 0 2359
    "TCGA-3U-A98H-01" 1 1156
    "TCGA-TS-A7P3-01" 1  689
    "TCGA-LK-A4O2-01" 1   57
    "TCGA-TS-A7OU-01" 1 1675
    "TCGA-MQ-A6BR-01" 0 2090
    "TCGA-MQ-A4KX-01" 1 2459
    "TCGA-3U-A98J-01" 1  741
    "TCGA-TS-A8AV-01" 1    .
    "TCGA-MQ-A6BS-01" 1  608
    "TCGA-SC-AA5Z-01" 0  664
    "TCGA-YS-A95C-01" 1  133
    "TCGA-MQ-A4LC-01" 1 2790
    "TCGA-3H-AB3M-01" 1  885
    "TCGA-MQ-A4LJ-01" 1  709
    "TCGA-TS-A7P1-01" 1  563
    "TCGA-ZN-A9VP-01" 0  228
    "TCGA-UD-AABY-01" 1  843
    "TCGA-TS-A8AY-01" 1  469
    "TCGA-UD-AAC7-01" 1  406
    "TCGA-UD-AABZ-01" 1  197
    "TCGA-TS-A7P0-01" 1 1261
    "TCGA-ZN-A9VO-01" 0  261
    "TCGA-YS-A95B-01" 1   39
    end

  • #2
    It looks to me like you want to just censor all observations at ostime == 1200. You can do that in the -stset- command directly:
    Code:
    stset ostime, failure(os) exit(time 1200)
    You don't have to change os or ostime at all.

    Added: There are some values of ostime in your example data that shouldn't be there. -stset- will warn you about them and exclude them from analysis, but I will outline them here so you can perhaps fix them.

    Two observations have ostime == 0. If a person (or whatever the entities in your study are) has already failed by time 0, then they never actually enter in your study. You should just drop those observations.

    You have one observation with ostime missing. This, too, should never happen. If the person entered your study, even if you do not know when they eventually fail, you must have at some point observed them before they failed. (Otherwise they never entered your study in the first place.) Whatever that last time of observation before failure was, that is their ostime value, with os = 0 to show they are censored.
    Last edited by Clyde Schechter; 20 Aug 2023, 14:08.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      It looks to me like you want to just censor all observations at ostime == 1200. You can do that in the -stset- command directly:
      Code:
      stset ostime, failure(os) exit(time 1200)
      You don't have to change os or ostime at all.
      Definitely a very intelligent command -stset- is. I was trying to write expressions in the exit with exit(time cond(ostime....) etc. Thanks much, Clyde Schechter.

      Comment

      Working...
      X