Dear all,
Forgive me if this question has been posted and answered before, however I am really struggling with the command/program required to solve the STATA problem below. I really hope someone is able to help me.
My issue;
I have a categorical variable 'x' (coded: 0/1). For example:
This variable continues down into the millions. Now I need to extract specific data from this 'x' variable and this is where I am struggling.
I need to extract all the number of consecutive observations which are surrounded between 5 or more consecutive 'x'=1s before and after.
I guess this is best explained with an example. Therefore, for instance in the example above, I would require a list/output which includes the following 2 values; 4 and 3 - Since 4 values (ID = 9, 10, 11 and 12) are surrounded by 8 and 6 values of 1 and similarly 3 observations (ID = 19, 20 and 21) are surrounded by 6 and 5 values of 1.
Does anyone on here know how I can possibly do this? Thank you so much in advance.
Forgive me if this question has been posted and answered before, however I am really struggling with the command/program required to solve the STATA problem below. I really hope someone is able to help me.
My issue;
I have a categorical variable 'x' (coded: 0/1). For example:
ID | x |
1 | 1 |
2 | 1 |
3 | 1 |
4 | 1 |
5 | 1 |
6 | 1 |
7 | 1 |
8 | 1 |
9 | 0 |
10 | 0 |
11 | 0 |
12 | 0 |
13 | 1 |
14 | 1 |
15 | 1 |
16 | 1 |
17 | 1 |
18 | 1 |
19 | 0 |
20 | 1 |
21 | 0 |
22 | 1 |
23 | 1 |
24 | 1 |
25 | 1 |
26 | 1 |
27 | 0 |
28 | 1 |
29 | 1 |
. | . |
. | . |
. | . |
I need to extract all the number of consecutive observations which are surrounded between 5 or more consecutive 'x'=1s before and after.
I guess this is best explained with an example. Therefore, for instance in the example above, I would require a list/output which includes the following 2 values; 4 and 3 - Since 4 values (ID = 9, 10, 11 and 12) are surrounded by 8 and 6 values of 1 and similarly 3 observations (ID = 19, 20 and 21) are surrounded by 6 and 5 values of 1.
Does anyone on here know how I can possibly do this? Thank you so much in advance.
Comment