calculating time difference between sub groups in a data set

#1
Calculat time difference between two events in data set

Hi everyone,
I am a beginner and I have a data set that I want to analyze, but I don't know if it is possible to do what I want using stata.
I have data in the format
Code:
No	time             event          user      network  
1	9:02:01     associate        01          n-03            
2 	9:05:00     associate        01          n-02             
3	9:05:05     disassociate    01          n-03              
4	9:08:02     disassociate    02          n-02              
5	9:08:00     associate        01          n-01              
6 	9:30:02     associate        01          n-01             
7	9:35:35     associate        01          n-04             
8 	9:30:05     disassociate    01          n-01                
9	9:35:27     disassociate    01          n-01                
10 	9:01:00     associate        02          n-05           
11	9:10:47     disassociate    02          n-05
I am trying to calculate the time between each association and disassociation for each user per network. The output should be something like that

Code:
No	time             event          user      network       elapsed_time(sec)
1	 9:02:01     associate        01          n-03            184
2	 9:05:00     associate        01          n-02            178
3  	 9:05:05     disassociate    01          n-03               .
4	 9:08:02     disassociate    02          n-02               .
5  	 9:08:00     associate        01          n-01            1315
6  	 9:30:02     associate        01          n-01             325
7	 9:35:35     associate        01          n-04                .
8	 9:30:05     disassociate    01          n-01                .
9	 9:35:27     disassociate    01          n-01                .
10 	 9:01:00     associate        02          n-05              587
11 	 9:10:47     disassociate    02          n-05                .
the problem that I'm facing is that there is no pattern for the association - dissociation events so I need a way to go through the observation, each time an event == association, it will start looking for the disassociation for the same user with the same network.
but as in 8 and 9 there are two disassociation events for the same user with the same network, so to avoid calculating the wrong elapsed time between 6 and 9 by using 8 instead of 9, I thought maybe it should delete the disassociation event after calculating the time, so that it won't be used twice??

So can you please help me if this is possible to do with stata , and if possible how?

Thank you
 
Last edited: