Kaplan-Meier and predicted survival plot

Here, we will plot the Kaplan-Meier observed survival curves and compare them to the Cox predicted curves for the same x-variable. If the observed values are close to the predicted values, it is less likely that there is a violation of the proportional hazards assumption.

Note
Again, this command does not work very well for continuous x-variables, so we will stick to the categorical ones.
More information
help stcoxkm

Practical example

The first step is re-run a Cox regression model. We will start with the simple one that we did for sex. The quietly option is included in the beginning of the command to suppress the output. After this, we use the stcoxkm command.

quietly stcox sex if pop_cox==1, noshow
stcoxkm, by(sex)

These curves overlap rather nicely in terms of the observed and predicted values.

We can produce the curves also for our variable marstat40. The quietly option is included in the beginning of the command to suppress the output.

quietly stcox ib1.marstat40 if pop_cox==1, noshow

Then we use the stcoxkm command.

stcoxkm, by(marstat40)

Overall, the observed and predicted values overlap rather OK. There are some exceptions, especially when it comes to the widowed.