You are on page 1of 2

If you want to

Tell STATA you have a censored outcome with

observation time obstime and event indicator
Graph a Kaplan-Meier Survival curve

Survival in STATA
then use command.

stset obstime, failure(status)

sts graph

Graph a smoothed curve of the baseline

hazard function using kernel density
estimation (based on the data, not any
List Kaplan-Meier survival estimates

sts graph

Perform a logrank test of equality of survival

Fit a Cox Proportional Hazards model

sts test varname

sts list

stcox predictor list

useful options (things you put after

the comma)
some exist in STATA, but you wont
need them currently
by(varname) allows you to graph
separate survival curves on same plot
by level of varname
gwood adds Greenwood 95% CIs around
the survival curve
hazard makes a graph of baseline
hazard instead of K-M survival curve
cihazard adds confidence bands around
hazard function
by(varname) lists K-M survival
estimates by levels of varname
wilcoxon allows you to do a WilcoxonBreslow test instead of a logrank test
nohr gives estimated beta coefficients
instead of hazard ratios
robust provides robust standard error
cluster(id) lets STATA know you have
dependent data by id
schoenfeld(varname*) stores Schoenfeld
residuals for each observation in a
variable for each predictor in
predictor list
scaledsch(varname*) stores scaled
Schoenfeld residuals
mgale(varname) stores Martingale
residuals for each observation
basesurv(varname) stores estimates of
baseline survival in varname
basehc(varname) stores estimates of
baseline hazard in varname

Test the Proportional Hazards assumption

(after fitting a Cox model)


Plot a ln(-ln(S(t)) plot

(after fitting a Cox model)
Plot survival predicted by Cox model with
observed survival by Kaplan-Meier
Plot estimates of the hazard (survival)
function at mean values of covariates (after
fitting a Cox model)


Plot Scaled Schoenfeld residuals vs. time and

look for flatness of the smooth (flat smooth
implies PH is okay for that covariate,
increasing or decreasing smooth implies
problems with PH)
Plot Martingale residuals for continuous
covariates and look for shape of smooth (flat
smooth implies functional form for covariate
is okay, curved smooth implies transforming
covariate in the model)

lowess varname _t
(here, varname is the stored scaled
Schoenfeld residuals corresponding to
covariate you are checking for PH)


lowess varname covariate

(here, varname is the stored
Martingale residuals, covariate is a
continuous covariate)

global test requires having specified

schoenfeld() in stcox
individual tests require having
specified scaledsch() in stcox
by(varname) specifies plotting by
levels of varname
by(varname) specifies plotting by
levels of varname
hazard is for plotting hazard function
(requires basehc() option to have been
specified in stcox)
survival is for plotting survival
function (requires basesurv() to have
been specified in stcox)
at(varname=#) allows plotting of curve
at covariate values specified by
at1(varname=#) allows you to plot
curve for another set of covariates on
same plot as at()
range(startnum endnum) allows you to
plot in a range between startnum and
endnum (useful for zooming in on plots
to get survival estimates)
bwidth(#) allows bandwidth
specification by a number #
(lower bandwidth makes curve try and
fit each data point more)
bwidth(#) allows bandwidth
specification by a number #
mean uses running-mean smoothing
instead of least-squares smoothing
(might want to do this when plotting
Martingale residuals)