help for survtime                                        (see also:  [R] stset)

Survival Time for use in stset

survtime [if exp] [in range] , events(varlist) censors(varlist) [generate(newvarname) sequential origin(varlist) addone]

NOTE: if generate(newvarname) is not used survtime will create or overwrite two variables called event_d: the first occurring date & event_i: the corresponding event indicator.


survtime finds the first occurring date of a list of events and censor dates and creates one variable event_d (or newvariable_d) for the date and a second variable event_i (or newvariable) indicating the status of that date as an event (1,2,...) or a censor (0) of types provided in events(varlist) and censors(varlist), respectively.

survtime was written with meaningful date (see dates) variables in mind. There is no check made for compatible numeric variables specified in events(varlist), censors(varlist), or origin(varname).

stset will use the resulting variable and event indicator. Example syntax of stset following survtime:

stset event_d [if exp] [in range] [, fail(event_i==numlist) origin(varname) scale(#) id(varname)].

Options generate(newvarname) specifies that new variables be created. The date will have the suffix _d added. The event indicator will have no suffix added. By default event_d and event_i will be created or overwritten.

sequential specifies that the events(varlist) are in descending order of interest and values 1,2,... will be so assigned and labeled indicating which event occurs first. Tied events will take the preceding event type. If sequential is not specified all events(varlist) get the value, 1.

origin(varname) specifies that the number of elapsed days be found from this origin. It will contain the number gotten by subtracting the provided origin from the event or censor date. The resulting variable will reflect this in its label. If this option is used it is not necessary to use the origin() option in stset.

addone specifies that one be added to the interval. If this option is specified without origin(varname), zero is used as the origin.

[if exp] [in range] options result in missing values for records excluded thereby. In general, it is recommend that the analysis set be defined in stset, or by some other means, rather than in survtime. If timevar in stset contains missing values stset responds by indicating probable error, which can mask substantial information about survival data. This, however, does not matter if survtime is used without stset to find observation time for a certain subset.


. survtime , e(die dmarrel) c(dlast cutoff) gen(dfs) seq . stset dfs_d, failure(dfs==1/2) origin(begin_d) scale(365) id(idnumber)

. survtime , e(die dmarrel) c(dlast cutoff) gen(dfs) . stset dfs_d, failure(dfs==1) origin(begin_d) scale(365) id(idnumber)


Allen Buxton, Assistant Statistician Children's Oncology Group Arcadia, CA

Also see

Manual: [R] stset

On-line: help for stset survtime