Hi,
I have survival data and I would like to change the structure of the dataset.
stnum=patient id
survtime=time to event stat=event 0/1
loctime = time to event lcens =0/1
axltime=time to event acens=0/1
distime =time to event dcens=0/1
maltime=time to event mcens =0/1
first_t =time to first event first_e=0,1,2,3,4,5 where 0=censoring and 1-5 define the type of event as shown in the variables above
Please see data structure below for 20 obs

----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int stnum float survtime byte stat float loctime byte lcens float axltime byte acens float distime byte dcens float maltime byte mcens float first_t byte first_e
 1   8.26831 0   8.26831 0   8.26831 0   8.26831 0   8.26831 0   8.26831 0
 2  6.173853 0  6.173853 0  6.173853 0 1.3524983 1  6.173853 0 1.3524983 4
 3  7.175907 0  7.175907 0  7.175907 0  7.175907 0  7.175907 0  7.175907 0
 4  9.505818 0  9.505818 0  9.505818 0  9.505818 0  9.505818 0  9.505818 0
 5   9.09514 0   9.09514 0   9.09514 0   9.09514 0   9.09514 0   9.09514 0
 6  8.095825 1  8.095825 0  8.095825 0  8.095825 0  8.095825 0  8.095825 1
 7  .7255304 1  .7255304 0  .7255304 0  .6023272 1  .7255304 0  .6023272 4
 8  4.963724 0  4.963724 0  4.963724 0  4.963724 0  4.963724 0  4.963724 0
 9  8.848734 0  8.848734 0  8.848734 0  8.848734 0  8.848734 0  8.848734 0
10  5.163587 0  5.163587 0  5.163587 0  5.163587 0  5.163587 0  5.163587 0
11  8.837782 0  8.837782 0  8.837782 0  8.837782 0  8.837782 0  8.837782 0
12   8.99384 0   8.99384 0   8.99384 0   8.99384 0   8.99384 0   8.99384 0
13  7.195072 0  7.195072 0  7.195072 0  7.195072 0  7.195072 0  7.195072 0
14  9.385352 0  9.385352 0  9.385352 0  7.909651 1  .9418207 1  .9418207 5
15  9.002053 0  9.002053 0  9.002053 0  9.002053 0  9.002053 0  9.002053 0
16 1.0349076 1 1.0349076 0 1.0349076 0  .7392197 1 1.0349076 0  .7392197 4
17  .3422314 1  .3422314 0  .3422314 0  .3422314 0   .312115 1   .312115 5
18  9.475701 0  9.475701 0  9.475701 0  9.475701 0  2.625599 1  2.625599 5
19   9.54141 0   9.54141 0   9.54141 0   9.54141 0   9.54141 0   9.54141 0
20  9.308693 0  9.308693 0  9.308693 0  9.308693 0  9.308693 0  9.308693 0
end
I would like to restructure the data in 2 alternative ways:

1. To expand the data in a way that each patient appears according to the number of events she/he had and the corresponding times 1 and 2. This would comply with the Andersen-Gill and the Prentice-William-Petersen models.
For example, stnum==1 had 0 events so time1=0 and time2=8.26831 with overall status==0 and event_type==0. This patient had no event and was cencored at time 8.26831. This patient will appear only once.
Patient stnum==2 had 2 events and will have to appear 3 times
time1 time 2 status event_type stnum
0 1.3524983 1 1 2
0 ​​​1.3524983 1 4 2
1.3524983 6.173853 0 0 2

ect

2. I would like to the create a structutre which would comply with the Wei-Lin-Weissfel model where each patient has 6 observations equal to the number of all possible event types.
stnum==1
event_type time status
0 8.26831 0
1 8.26831 0
2 8.26831 0
3 8.26831 0
4 8.26831 0
5 8.26831 0

stnum==2
event_type time status
0 6.173853 0
1 1.3524983 1
2 6.173853 0
3 6.173853 0
4 1.3524983 1
5 6.173853 0

I hope this is clear. any help would welcome.
Thank you,
Nikos