Good afternoon, I have a problem in constructing my dataset on stata. I have repeated events for each subject together with intervals of time in which an event happens or not. They are mothers which are followed to study their career breaks. I also have the total number of children they have and the time of birth for each child, for example:
id event time0 time timefirstchild timesecondchild #children
1 1 0 10 5 8 2
1 1 15 20 5 8 2
1 0 24 32 5 8 2
2 1 0 7 9 14 2
2 1 8 12 9 14 2
2 1 13 17 9 14 2
2 0 20 23 9 14 2
3 1 0 13 . . 0
3 0 14 18 . . 0
I would like to split each time span (time0-time) into segments defined by time0-timefirstchild, timefirstchild-timesecondchild and so on. Also I'd like to update a counting variable which increases of one each time the mother has a baby, in order to update her number of children over time. For example, I would like to get:
id event time0 time timefirstchild timesecondchild #children childrencount
1 1 0 5 5 8 2 1
1 1 8 15 5 8 2 2
1 0 15 20 5 8 2 2
2 1 0 7 9 14 2 0
2 1 8 9 9 14 2 1
2 1 9 12 9 14 2 1
2 0 13 14 9 14 2 2
2 0 14 17 9 14 2 2
2 0 20 23 9 14 2 2
3 1 0 13 . . 0 0
3 0 14 18 . . 0 0
Do you have any suggestion?
Thank you all in advance.
Anna
0 Response to splitting time span
Post a Comment