← Back to Software
kmplot
Reporting & VisualizationPublication-ready Kaplan-Meier survival curves with risk tables, CI bands, and median lines
Version 1.0.2 | 2026-04-22
kmplot turns an stset dataset into publication-ready survival graphics with sensible defaults for confidence intervals, risk tables, median lines, censor marks, and log-rank p-values. It keeps the flexibility of native Stata graphics while removing most of the repetitive styling work that usually follows sts graph.
Requirements
- Stata 16 or later
- Data already declared with
stset
Installation
capture ado uninstall kmplot
net install kmplot, from("https://raw.githubusercontent.com/tpcopeland/Stata-Tools/main/kmplot") replace
Commands
| Command | Description |
|---|---|
kmplot |
Draw Kaplan-Meier or cumulative incidence curves with publication-oriented defaults |
How It Works
kmplotreads the currentstsetdefinition, so there is no separate model-fitting step.- Add
by()when you want one curve per group.pvalueonly applies whenby()is present. - Add
failurewhen you want cumulative incidence, that is1 - S(t), instead of survival. - Add
ci,risktable,median,medianannotate,censor, andexport()as you build up a manuscript-ready figure.
Worked Examples
1. Basic Kaplan-Meier curve
sysuse cancer, clear
stset studytime, failure(died)
kmplot
2. Stratified publication-style figure
This adds the features that usually matter in a manuscript figure: confidence bands, a number-at-risk table, median reference lines, censor marks, and the log-rank p-value.
sysuse cancer, clear
stset studytime, failure(died)
kmplot, by(drug) ci risktable median medianannotate pvalue censor
3. Cumulative incidence instead of survival
sysuse cancer, clear
stset studytime, failure(died)
kmplot, by(drug) failure risktable
4. Export the finished graph directly
sysuse cancer, clear
stset studytime, failure(died)
kmplot, by(drug) ci median export(km_figure.pdf, replace)
Key Features
- Shaded confidence bands or dashed confidence-interval lines via
cistyle(band)andcistyle(line) - Number-at-risk tables, with optional cumulative event counts
- Median survival reference lines and optional note annotations
- Censor marks with thinning through
censorthin() - Direct graph export through
export() - Pass-through support for standard
twowaygraph options
Version History
- 1.0.2 (2026-04-22): Varabbrev wrapper refactored to cover all exit paths (syntax, validation, and main logic). Fixed literal-quote rendering in user-supplied ytitle/xtitle/note options. Removed unnecessary
set more off. Export success message now guarded byconfirm file. - 1.0.1 (2026-04-10): Initial Stata-Tools release with Kaplan-Meier, cumulative-incidence, risk-table, censoring, median-line, and export support
Author
Timothy P Copeland, Karolinska Institutet