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]
Re: st: Re: Reshape and foreach for multiple failure analysis
From
Phil Clayton <[email protected]>
To
[email protected]
Subject
Re: st: Re: Reshape and foreach for multiple failure analysis
Date
Wed, 8 Feb 2012 17:10:47 +1100
Something like this?
Phil
* input data
clear
input ID Group E1 E2 E3 E4 t_end
1 1 2 . . . 48
2 5 6 12 18 . 36
end
* reshape to long format
* the final time is the last "failure" time so rename accordingly
rename t_end E5
reshape long E, i(ID) j(failnum)
rename E time
drop if missing(time) // don't need these records
gen byte status=failnum!=5 // they're all failures apart from failnum 5
* time0 is the origin
gen time0=0
bysort ID (failnum): replace time0=time[_n-1] if _n>1
* failnum can now just be a simple counter
bysort ID (failnum): replace failnum=_n
* display resulting data
order ID Group time0 time status failnum
list, sepby(ID)
On 08/02/2012, at 4:18 PM, [email protected] wrote:
> Hello everyone-
>
> I am attempting to set up longitudinal data for multiple failure
> analysis; I have consulted the Stata site (FAQ: Analysis of multiple
> failure-time survival data) but have been unsuccessful on the reshape
> to get there.
>
> Current:
>
> Where E1 to E4 are events, occurring at the specified number of weeks
> from t0, and t_end is the total weeks of follow-up.
>
> ---------------------------------------------------------------------
> ID Group E1 E2 E3 E4 t_end
> 1 1 2 . . . 48
> 2 5 6 12 18 . 36
> ...
> ---------------------------------------------------------------------
>
> Needed (analogous to section 3.2.3 of the FAQ):
>
> Where _time_ is the time elapsed from t0, _status_ is (1=event; 0=end
> of observation), and _failnum_ is failure number.
>
> ----------------------------------------------------------
> ID Group time0 time status failnum
> 1 1 0 2 1 1
> 1 1 2 48 0 2
> 2 1 0 6 1 1
> 2 5 6 12 1 2
> 2 5 12 18 1 3
> 2 5 18 36 0 4
> ...
> ----------------------------------------------------------
>
> I have tried a whole range of _reshape_ options plus some _foreach_
> loops with _egen_ to create the new matrix, but have been stymied.
>
> Any suggestions would be superb!
>
> thanks
> Andrew Lover
>
> ___________________________________________________________
> Epidemiologist
> Centre for Infectious Disease Epidemiology Research (CIDER)
> Saw Swee Hock School of Public Health
> National University of Singapore
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/