← All posts

Survival Analysis in Clinical Epidemiology Stata Code dominant: From Kaplan–Meier to Cox Regression (Non-parametric, Semi-parametric)

Clinical Epidemiology ResearchUniqcret doctor knowledgesMethodology and Research DesignPrognosis [Methodology]Data Analytics or StatisticsStata [Data Analytics]
On this page

Introduction

Survival analysis is used when time matters.

We are not only interested in whether an event happens, but also when it happens, and we must correctly handle censoring (patients who do not experience the event during follow-up).


1. Non-parametric Survival Analysis

(Describe and compare survival — no model assumptions)

Step 1: Survival-time setting (stset)

Before doing anything, we must tell Stata:

stset time, failure(event==1)

👉 This creates the survival data structure. 👉 Everything in survival analysis starts here.


Step 2: Life table analysis (sts list)

sts list
sts list, by(group)

What this does:

✅ Good for:

📌 Conceptually:

“How many patients are still under observation at each time?”


Step 3: Kaplan–Meier curves (sts graph)

Kaplan–Meier is a graphical form of sts list.

Survival curve

sts graph, survival
sts graph, survival by(group)

Shows:

Failure curve (cumulative incidence)

sts graph, failure
sts graph, failure by(group)

Shows:

📌 Important:


Step 4: Log-rank test (sts test)

sts test group

What it does:

Interpretation:

“Are the survival curves statistically different?”

✅ You can compare:

❌ What it does NOT do:


Summary: Non-parametric methods

MethodPurpose
stsetDefine time & event
sts listLife table (numbers at risk)
sts graphKaplan–Meier curves
sts testCompare curves (p-value only)

2. Semi-parametric Survival Analysis

Cox Proportional Hazards Regression (stcox)

Now we move from description to effect estimation.

What Cox regression tells us

stcox exposure

Cox regression answers:

“How much higher or lower is the risk over time?”

It reports a Hazard Ratio (HR).

Interpretation of Hazard Ratio

HRMeaning
HR = 1No difference
HR > 1Higher risk
HR < 1Lower (protective) risk

Example interpretation:

“Cryosurgery reduced the hazard of recurrence by 52% (HR 0.48).”


Adjusted Cox regression (control confounders)

stcox exposure age sex i.other

This answers:

“What is the effect of exposure after adjusting for other factors?”

📌 Key strength of Cox:


Relationship to non-parametric methods

MethodQuestion answered
Kaplan–MeierWhat does survival look like?
Log-rankAre curves different?
CoxHow large is the effect?

3. Full Parametric Survival Models

(Know they exist — no detail needed)

Examples:

In Stata:

streg exposure, dist(weibull)

Key idea:

📌 For beginners:

Just know that parametric models exist You do not need details at this stage


4. Flexible Parametric Survival Models

(Know they exist — no detail needed)

Examples:

Purpose:

📌 For now:

“These are advanced extensions of survival models.”

No need to go deeper for introductory learning.


Big Picture Summary (Very Important)

LevelMethodWhat it does
Non-parametricstsDescribe & compare survival
Semi-parametricstcoxEstimate hazard ratios
ParametricstregModel survival with assumptions
Flexible parametricAdvancedComplex hazard shapes


One-sentence takeaway (exam-ready)

Kaplan–Meier describes survival, log-rank tests differences, Cox regression estimates effects, and parametric models add assumptions.

0
Message for International and Thai ReadersUnderstanding My Medical Context in ThailandRead more →Message for International and Thai ReadersUnderstanding My Broader Content Beyond MedicineRead more →

Comments

No comments yet. Be the first to share your thoughts.

Sign in to comment