Dear all, I could really use your help on this one!
I have a dataset that has data of 2000 babies (baby_id). Each baby was followed from birth for a month, twice a day- so each baby should have around 60 time points of data (time). Although many of them don't. At each of those time points, there is a variables that is "exclusive breastfeeding" (ex_bf). I need to calculate the time to exclusive breastfeeding, meaning the moment in time that the baby passes from not being exclusively breastfed (0), to being exclusively breastfed(1).
The data is stored in the long format.
id time ex_bf
1 0 .
1 1 0
1 4 1
2 2 0
3 1 0
3 5 0
3 7 .
4 0 0
4 1 0
4 2 1
4 3 1
5 2 .
6 0 0
6 1 8
6 2 9
I've been trying to treat time categorically and say that ex_bf[_n-1]==0, and so on [_n-2] for all the previous times, but I gave up because there has to be a better way to go around it.
I would really appreciate your input since I need to submit this analysis ASAP.
Thank you!
I have a dataset that has data of 2000 babies (baby_id). Each baby was followed from birth for a month, twice a day- so each baby should have around 60 time points of data (time). Although many of them don't. At each of those time points, there is a variables that is "exclusive breastfeeding" (ex_bf). I need to calculate the time to exclusive breastfeeding, meaning the moment in time that the baby passes from not being exclusively breastfed (0), to being exclusively breastfed(1).
The data is stored in the long format.
id time ex_bf
1 0 .
1 1 0
1 4 1
2 2 0
3 1 0
3 5 0
3 7 .
4 0 0
4 1 0
4 2 1
4 3 1
5 2 .
6 0 0
6 1 8
6 2 9
I've been trying to treat time categorically and say that ex_bf[_n-1]==0, and so on [_n-2] for all the previous times, but I gave up because there has to be a better way to go around it.
I would really appreciate your input since I need to submit this analysis ASAP.
Thank you!
Comment