Dear Colleagues
I have a variable with the following values:
1
1
1
0
0
1
1
1
1
0
1
1
1
1
0
0
1
1
I want stata to identify the longest spell/s (i.e. 4 consecutive 1s) and just keep those 1s and replace the other 1s (in the groups of 3 1s and 2 1s) with zeros.
I can also achieve that by creating a new variable where it keeps the 1s with the longest spell, i.e. just the groups of 1s with the longest spells, and doesn't have the other groups of 1s. That is:
0
0
0
0
0
1
1
1
1
0
1
1
1
1
0
0
0
0
After that, I would like to be estimate the probability of being in a spell of 4 1s, without conflating spells - thus I don't want to include the two sets of 4 1s. I can either ask Stata to delete the 'extra' set of 4 1s, or I can ask Stata to just use one set of 4 1s to estimate the probability.
I'd be very grateful for your advice how to achieve this.
Many thanks Sanghamitra
I have a variable with the following values:
1
1
1
0
0
1
1
1
1
0
1
1
1
1
0
0
1
1
I want stata to identify the longest spell/s (i.e. 4 consecutive 1s) and just keep those 1s and replace the other 1s (in the groups of 3 1s and 2 1s) with zeros.
I can also achieve that by creating a new variable where it keeps the 1s with the longest spell, i.e. just the groups of 1s with the longest spells, and doesn't have the other groups of 1s. That is:
0
0
0
0
0
1
1
1
1
0
1
1
1
1
0
0
0
0
After that, I would like to be estimate the probability of being in a spell of 4 1s, without conflating spells - thus I don't want to include the two sets of 4 1s. I can either ask Stata to delete the 'extra' set of 4 1s, or I can ask Stata to just use one set of 4 1s to estimate the probability.
I'd be very grateful for your advice how to achieve this.
Many thanks Sanghamitra
Comment