Announcement

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

  • Defining a new survival time variable for stset

    Hi I'm trying to define a survival time variable which is time to death, loss of follow up or time to infection(whichever comes first)

    How do I come up with a command to define this variable?

    Most tutorials have shown how to define if there's one event of interest e.g.

    Code:
    gen survivaltime=(date of death)-(date of start of follow up)
    Would appreciate any advice thanks

  • #2
    Well, it depends on how your data set is organized. I'll guess that you have a wide layout with one observation per person, a variable showing time to death (missing if the person didn't die), time to infection (again, missing if no infection occurred), and time to loss of follow-up (again, missing if follow-up remains ongoing). In that case:
    Code:
    gen survivaltime = min(date_of_death, date_of_infection, date_of_loss_to_follow_up) - date_of_start_of_follow_up
    If that is not how your data set is organized, then you need to post back with example data. (And please, in the future, whenever you are asking for help with code, just show example data. Occasionally the answer can be given without it, but that is a small minority of situations. Posting a question about code with no example data is mostly a waste of your time and other people's time.) When posting back with example data, remember to be sure to use the -dataex- command for that purpose. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Note: if you are reluctant to show example data because of confidentiality issues, take your real data set, -drop- observations so as to leave you with smaller data set that is representative of the whole, and then in the data editor overwrite the values of the variables with other numbers that are plausible but not the real data, and change any ID variables to just sequential numbers 1, 2, 3. (-egen new_ID = group(ID)- will do that, followed by -drop ID-.) That way nothing confidential will be leaked, but the structure and nature of the data are shown. This will usually suffice because the answers to most coding questions don't depend on the values of the data, but only on how the data are organized in the data set.

    Comment


    • #3
      Thank you and apologies for not including an example data. Your assumption is right and this is helpful, many thanks

      Comment

      Working...
      X