Hello I have the following dataset but I am really stuck on how to do the hierarchy for few weeks actually. Any suggestions would be GREATLY appreciated!! Thank you!
Here are the rules:
If the group contains > 20 on any instance or then it should be code as 'TOO HIGH' or if it is between 16-20 TWICE in a row
If the group is between 11 through 15 twice in a row, then it should be 'HIGH'
If the group is between 6 through 10 twice in a row, then it should be 'Low'
If the group is between 1 through 5 twice in a row, then it should be 'Normal'
Basically if the two consequentive events don't happen by top hierarchy (too high), you skip to the next level (high, low, normal, etc)
Here is the dataset
ID | value | seq_id |
1 | 3 | 1 |
1 | 1 | 2 |
1 | 2 | 3 |
1 | 4 | 4 |
1 | 1 | 5 |
2 | 20 | 1 |
2 | 21 | 2 |
2 | 5 | 3 |
3 | 1 | 1 |
3 | 6 | 2 |
3 | 7 | 3 |
3 | 1 | 4 |
3 | 4 | 5 |
3 | 21 | 6 |
3 | 17 | 7 |
3 | 1 | 8 |
3 | 2 | 9 |
4 | 6 | 1 |
4 | 9 | 2 |
4 | 12 | 3 |
4 | 13 | 4 |
5 | 1 | 1 |
5 | 6 | 2 |
5 | 7 | 3 |
5 | 14 | 4 |
5 | 20 | 5 |
6 | 11 | 1 |
6 | 12 | 2 |
6 | 25 | 3 |
6 | 16 | 4 |
6 | 21 | 5 |
Here's the output I am looking for:
ID | value | seq_id | output |
1 | 3 | 1 | Normal |
1 | 1 | 2 | |
1 | 2 | 3 | |
1 | 4 | 4 | |
1 | 1 | 5 | |
2 | 20 | 1 | Too High |
2 | 21 | 2 | |
2 | 5 | 3 | |
3 | 1 | 1 | |
3 | 6 | 2 | |
3 | 7 | 3 | |
3 | 1 | 4 | |
3 | 4 | 5 | |
3 | 21 | 6 | Too High |
3 | 17 | 7 | |
3 | 1 | 8 | |
3 | 2 | 9 | |
4 | 6 | 1 | |
4 | 9 | 2 | |
4 | 12 | 3 | High |
4 | 13 | 4 | |
5 | 1 | 1 | |
5 | 6 | 2 | Low |
5 | 7 | 3 | |
5 | 14 | 4 | |
5 | 19 | 5 | |
6 | 11 | 1 | |
6 | 12 | 2 | |
6 | 25 | 3 | Too High |
6 | 16 | 4 | |
6 | 21 | 5 | |