Announcement

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

  • identify treatment changes

    Hello, everyone

    I need to replace the date_stop of treat=="Cladribine" or treat=="Alemtuzumab" with the date_start of the next treatment that the patient receives.

    clear
    input double REFERENCE_DATE float(date_start date_stop alias) str8 no_treat float id
    22166.79127314815 19768 20342 10 "" 1
    22166.79127314815 20349 21663 5 "" 1
    22166.79127314815 21671 . 22 "" 1
    22047.680081018516 16997 . 10 "" 2
    22047.702465277776 . . . "No-treat" 3
    22049.722025462965 . . . "No-treat" 4
    22060.65284722222 . . . "No-treat" 5
    22046.94578703704 20439 20653 20 "" 6
    22046.94578703704 20667 . 1 "" 6
    22046.84505787037 16847 20096 10 "" 7
    22046.84505787037 20103 21080 5 "" 7
    22046.84505787037 21503 22084 5 "" 7
    22046.84505787037 22144 . 17 "" 7
    22048.214120370372 . . . "No-treat" 8
    22047.348738425928 22039 . 5 "" 9
    22162.813275462962 . . . "No-treat" 10
    22046.838946759257 . . . "No-treat" 11
    22060.685555555552 . . . "No-treat" 12
    22053.709814814814 19769 . 10 "" 13
    22060.825636574074 . . . "No-treat" 14
    22046.946851851855 21927 . 24 "" 15
    22046.885474537034 15751 17275 10 "" 16
    22046.885474537034 17275 17660 12 "" 16
    22046.885474537034 17846 20436 8 "" 16
    22046.885474537034 20491 20496 1 "" 16
    22046.885474537034 20856 20858 1 "" 16
    22046.885474537034 22657 . 22 "" 16
    22060.678912037038 . . . "No-treat" 17
    22165.468090277776 22043 22756 16 "" 18
    22165.468090277776 22789 . 17 "" 18
    22046.939884259256 17920 21145 11 "" 19
    22046.939884259256 21151 23153 16 "" 19
    22046.939884259256 23181 . 17 "" 19
    22046.844710648147 18642 20917 10 "" 20
    22046.844710648147 20924 22616 24 "" 20
    22046.844710648147 22670 . 17 "" 20
    22046.853530092594 . . . "No-treat" 21
    22047.606782407405 . . . "No-treat" 22
    22166.51505787037 . . . "No-treat" 23
    22047.352013888885 17119 20142 11 "" 24
    22047.352013888885 . . 14 "No-treat" 24
    22046.904953703706 21734 21772 3 "" 25
    22046.904953703706 22119 22153 3 "" 25
    22063.81465277778 21945 . 5 "" 26
    22046.88846064815 21958 . 24 "" 27
    22049.80988425926 15627 20349 10 "" 28
    22049.80988425926 17498 17846 24 "" 28
    22049.80988425926 20349 . 24 "" 28
    22060.767638888887 . . . "No-treat" 29
    22047.38324074074 . . . "No-treat" 30
    22060.670057870368 15522 17362 10 "" 31
    22060.670057870368 17590 . 10 "" 31
    22047.487812500003 15301 20254 10 "" 32
    22047.487812500003 20286 21533 5 "" 32
    22047.487812500003 21570 . 17 "" 32
    22047.626388888886 22453 . 5 "" 33
    22061.35744212963 17835 21868 10 "" 34
    22046.872719907406 21672 21825 24 "" 35
    22046.872719907406 21846 22480 5 "" 35
    22046.872719907406 22250 . 14 "" 35
    22046.872719907406 22487 . 17 "" 35
    22060.844837962963 16091 22238 10 "" 36
    22060.844837962963 22293 . 24 "" 36
    22163.432962962965 . . . "No-treat" 37
    22161.850555555553 . . . "No-treat" 38
    22060.663518518515 . . . "No-treat" 39
    22046.832384259258 14921 22432 10 "" 40
    22046.832384259258 22439 . 17 "" 40
    22046.86273148148 . . . "No-treat" 41
    22047.42271990741 . . . "No-treat" 42
    22046.87584490741 21635 . 17 "" 43
    22046.845671296294 21781 . 5 "" 44
    22046.881782407407 21476 . 22 "" 45
    22161.850613425922 21035 23072 24 "" 46
    22161.850613425922 23099 . 18 "" 46
    22161.850613425922 . . 14 "No-treat" 46
    22161.850613425922 . . 14 "No-treat" 46
    22060.716770833336 16967 . 11 "" 47
    22046.956388888888 . . . "No-treat" 48
    22050.52585648148 22008 . 16 "" 49
    22060.76650462963 18063 18421 10 "" 50
    22060.76650462963 18428 18659 10 "" 50
    22060.76650462963 21357 21397 5 "" 50
    22060.76650462963 21497 . 16 "" 50
    22164.54167824074 21481 21579 5 "" 51
    22164.54167824074 21622 21689 8 "" 51
    22164.54167824074 21859 21879 8 "" 51
    22060.68136574074 . . . "No-treat" 52
    22060.712326388886 21144 21564 10 "" 53
    22060.712326388886 21571 22189 7 "" 53
    22060.712326388886 22238 . 16 "" 53
    22047.476793981485 14563 17448 10 "" 54
    22047.476793981485 17455 17485 16 "" 54
    22047.476793981485 17568 17920 12 "" 54
    22047.476793981485 18021 18085 8 "" 54
    22047.476793981485 19809 21035 24 "" 54
    22047.476793981485 21089 22263 7 "" 54
    22047.476793981485 22294 . 17 "" 54
    22046.813900462963 . . . "No-treat" 55
    22047.430833333332 13284 21641 11 "" 56
    end
    format %td REFERENCE_DATE
    format %dD_m_CY date_start
    format %dD_m_CY date_stop
    label values alias lab_alias
    label def lab_alias 1 "Alemtuzumab", modify
    label def lab_alias 3 "Cladribine", modify
    label def lab_alias 5 "Dimethyl fumarate", modify
    label def lab_alias 7 "Fingolimod", modify
    label def lab_alias 8 "Glatiramer Acetate", modify
    label def lab_alias 10 "Interferon Beta-1a", modify
    label def lab_alias 11 "Interferon Beta-1b", modify
    label def lab_alias 12 "Mitoxantrone", modify
    label def lab_alias 14 "NA", modify
    label def lab_alias 16 "Natalizumab", modify
    label def lab_alias 17 "Ocrelizumab", modify
    label def lab_alias 18 "Ofatumumab", modify
    label def lab_alias 20 "Peginterferon Beta-1a", modify
    label def lab_alias 22 "Rituximab", modify
    label def lab_alias 24 "Teriflunomide", modify

    Thank you very much !!

  • #2
    The following code is fairly complicated, because in some instances, the next start_date in the data for a given id represents the start of "No-treat". I assume that you don't want that to be the date at which Alemtuzumab or Caldribine is stopped. So a certain amount of work has to be done to determine the date of the next active treatment.

    Code:
    gen st_date = cond(inlist(alias, ., 14), `c(minfloat)', date_start)
    rangestat (min) next_date = date_start, by(id) interval(st_date 1 .)
    replace next_date = . if inlist(alias, ., 14)
    format next_date %td
    drop st_date
    
    by id (date_start), sort: replace date_stop = next_date if inlist(alias, 1, 3)
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC.

    Note: If you don't want to skip over the No-treat's to the next active treatment, then the code is simpler, it's just:
    Code:
    by id (date_start), sort: replace date_stop = date_start[_n+1] if inlist(alias, 1, 3)

    Comment


    • #3
      Thank you very much Clyde it has worked very well!!

      Comment

      Working...
      X