I have a long dataset that includes data on events. Each individual experiences many intervals, during which they may or may not experience an event. If they do experience an event, the variable "previous" indicates the number of previous events for that person. I would like to fill in the missing values of "previous" in the dataset. I have included a dataex example below that will help me explain. For person 1 (IDN=1), the variable "previous" should only take on a value of 0, since the person experienced no events. For person 2 (IDN=2), "previous" should equal 0 for intervals 1-15, should equal 1 for interval 17, and should equal 2 for intervals 20-26. And so on.
Can anyone help?
Thank you very much,
Sarah
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int idn byte interval float previous 1 1 . 1 3 . 1 4 . 1 5 . 1 6 . 1 7 . 1 8 . 1 9 . 1 10 . 1 11 . 1 12 . 1 13 . 1 14 . 1 15 . 1 16 . 1 17 . 1 18 . 1 19 . 1 20 . 1 21 . 1 22 . 1 23 . 1 24 . 1 25 . 1 26 . 2 1 . 2 3 . 2 4 . 2 5 . 2 6 . 2 7 . 2 8 . 2 9 . 2 10 . 2 11 . 2 12 . 2 13 . 2 14 . 2 15 . 2 16 0 2 17 . 2 18 1 2 19 2 2 20 . 2 21 . 2 22 . 2 23 . 2 24 . 2 25 . 2 26 . 4 1 . 4 3 . 4 4 . 4 5 . 4 6 . 4 7 . 4 8 . 4 9 . 4 10 . 4 11 . 4 12 . 4 13 . 4 14 . 4 15 . 4 16 . 4 17 . 4 18 . 4 19 . 4 20 . 4 21 . 4 22 . 4 23 . 4 24 . 4 25 . 4 26 . 6 3 0 6 4 . 6 5 . 6 6 . 6 7 . 6 8 1 6 9 2 6 10 3 6 11 4 6 12 5 6 13 6 7 1 . 7 3 0 7 4 . 7 5 . 7 6 . 7 7 . 7 8 . 7 9 . 7 10 . 7 11 . 7 12 . 7 13 . 7 14 . 7 15 . end
0 Response to Filling in missing values in long dataset using other non-missing values
Post a Comment