survsimis no longer developed. Its successor isavalon, from Red Door Analytics, for simulating survival data in R and Stata.avalonis a complete rewrite with a new syntax, not a new version ofsurvsim. This repository is an archive: version 4.0.11 is the final version, and can still be installed as described below.
Simulating time-to-event data in Stata, from parametric distributions, custom distributions, competing risks models and general multi-state models.
For an introductory seminar, see Simulating time-to-event data from parametric distributions, custom distributions, competing risk models and general multi-state models.
survsim simulates survival times from:
- A parametric distribution (
help survsim parametric): exponential, Gompertz and Weibull, and 2-component mixtures of them, with covariate effects and non-proportional hazards. - A user-defined distribution (
help survsim user): any hazard or cumulative hazard function, on the natural or the log scale, written in Mata; survival times are generated by numerical integration and root finding. - A fitted
merlinmodel (help survsim model). - A competing risks or general multi-state model (
help survsim msm): each transition has its own hazard function, a standard distribution or a user-defined one, with its own covariates and time-dependent effects.
- Stata 14.2 or later
moremata, for user-defined distributions and multi-state models:ssc install morematamerlinandmultistate, to simulate from a fittedmerlinmodel:ssc install merlinandssc install multistate
survsim can be installed from the SSC archive by typing:
ssc install survsim
To install directly from this GitHub repository, use:
net install survsim, from("https://raw.githubusercontent.com/mjcrowther/survsim/main/")Survival times from a Weibull distribution, with a binary treatment that has a log hazard ratio of -0.5, and censoring at 5 years:
clear set obs 1000 gen trt = rbinomial(1,0.5) survsim stime died, distribution(weibull) lambdas(0.1) gammas(1.5) covariates(trt -0.5) maxtime(5) stset stime, failure(died = 1) streg trt, distribution(weibull) nohr
Further examples, including competing risks and multi-state models, are in the help files: help survsim.
Version 4.0.11 (9 October 2026).
Bender R, Augustin T and Blettner M. Generating survival times to simulate Cox proportional hazards models. Statistics in Medicine 2005;24:1713-1723.
Beyersmann J, Latouche A, Buchholz A and Schumacher M. Simulating competing risks data in survival analysis. Statistics in Medicine 2009;28:956-971.
Crowther MJ and Lambert PC. Simulating complex survival data. The Stata Journal 2012;12(4):674-687.
Crowther MJ and Lambert PC. Simulating biologically plausible complex survival data. Statistics in Medicine 2013;32(23):4118-4134.
Crowther MJ. Simulating time-to-event data from parametric distributions, custom distributions, competing-risks models, and general multistate models. The Stata Journal 2022;22(1):3-24.
Jann, B. 2005. moremata: Stata module (Mata) to provide various functions. Available from http://ideas.repec.org/c/boc/bocode/s455001.html.
Copyright (C) 2011-2026 Michael J. Crowther.
Released under the GNU General Public License, version 3. See LICENSE.
The root-finding routine survsim_mm_root() in survsim_msm.ado is based on mm_root() from moremata by Ben Jann, which is distributed under the MIT License (Copyright (c) 2019 benjann). Its copyright and permission notice is reproduced in that file.