Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Antoine Terracol <[email protected]> |

To |
[email protected], [email protected] |

Subject |
Re: st: How do I simulate survival data? |

Date |
Fri, 04 Oct 2013 18:43:57 +0200 |

Hi Thomas, would the following code suit your needs?

Antoine -------------------------------------------------- clear set obs 1000 gen id=_n gen d=runiform()>0.5 g u=runiform() expand 36 bysort id : gen t=_n gen dt=d & t>=18 scalar alpha=.5 gen lambda=exp(-1+2*dt) bysort id (t) : gen e=t[_n-1] replace e=0 if t==1

gen time=( (ln(1-u)-sum)/(-lambda))^(1/alpha) bysort id (t) : gen cont=time>t bysort id (t) : gen sstop=sum(cont==0) drop if sstop>1 bysort id (t) : gen fail=sstop bysort id (t) : replace time=t if fail==0 bysort id (t) : keep if _n==_N stset time, id(id) fail(fail) sts graph ,by(d) --------------------------------------------------------------- On 03/10/13 19:16, Thomas Speidel wrote:

I'm trying to simluate survival data for illustrative purposes. I've never done this in Stata, so I'm not sure how I should proceed. The aim is to produce a Kaplan-Meier graph of a ficticious time to event process stratified by a binary variable. I would like the two lines to overlap until half time, and then starts diverging from one another. I also would like enough data to make the stair steps not too tall. I know how to generate the random time. But how do I generate the event and the binary variable so that it meets my conditions? Thanks.

-- Ce message a ete verifie par MailScanner pour des virus ou des polluriels et rien de suspect n'a ete trouve. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: How do I simulate survival data?***From:*Thomas Speidel <[email protected]>

- Prev by Date:
**Re: st: Recovering Jacobian from gmm estimate** - Next by Date:
**Re: st: Recovering Jacobian from gmm estimate** - Previous by thread:
**st: How do I simulate survival data?** - Next by thread:
**st: Using/Accessing discriminant function scores?** - Index(es):