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
Related Posts with splitting time span
Is collinearity a problem here?Dear Statalist users, I am trying to fit a linear regression model (Stata 15.0) with 5 different exp…
testing mixed model assumptionsHi everyone, I'm using mixed models the first time and I've got problems checking the model assumpt…
putdocx table - formatting numerical dataI am using putdocx table. Can I get columns formatted differently, some columns with numbers with 1 …
Generate variable: optimisation based on constraint defined by other variablesDear Stata users, I'm running Stata 15.1, and would like to generate a variable the values of which…
Converting string to date without any missing valuesHello, I have been trying to convert a string variable first_date into a date format with multiple …
Subscribe to:
Post Comments (Atom)
0 Response to splitting time span
Post a Comment