I have a panel and would like to count how often a unit changes a variable from 0 to 1 or 1 to 0 after being the same for a certain number of months before the switch and after the switch. Let's say for three months. Later I will want to be flexible about it and change it. Here is an example how the data looks like:
In this case there are two switches. One from 0 to 1 and one from 1 to 0.
id | month | switch |
1 | 1 | 0 |
1 | 2 | 0 |
1 | 3 | 1 |
1 | 4 | 0 |
1 | 5 | 0 |
1 | 6 | 0 |
1 | 7 | 1 |
1 | 8 | 1 |
1 | 9 | 1 |
1 | 10 | 0 |
1 | 11 | 0 |
1 | 12 | 0 |
Comment