A method for fitting piecewise proportional hazards models to censored survival data is described. Stratification is performed recursively, using a combination of statistical tests and residual analysis. The bootstrap is employed to keep the probability of a Type I error (the error of discovering two or more strata when there is only one) of the method close to a predetermined value. The proposed method can thus also serve as a formal goodness-of-fit test for the proportional hazards model. Real and simulated data are used for illustration.