Hello,
I am working on a panel data where the panel variable is called ID (unbalanced) and time variable is months with gaps.
I want to make a variable that groups my time variable months and ID for a two year period. However, as I have gaps in my dataset, I cannot figure out how to group it based on dates.
As you see in the example below there is a gap between 1980m7 and 1980m9, and thus this two year period only has 23 months. However, I still want the group to change at the beginning of 1982. Anyone know a solution to this?
I am working on a panel data where the panel variable is called ID (unbalanced) and time variable is months with gaps.
I want to make a variable that groups my time variable months and ID for a two year period. However, as I have gaps in my dataset, I cannot figure out how to group it based on dates.
As you see in the example below there is a gap between 1980m7 and 1980m9, and thus this two year period only has 23 months. However, I still want the group to change at the beginning of 1982. Anyone know a solution to this?
Months | ID | Return | Dummy variable(As I want it) |
1980m1 | 1 | -0.01 | 1 |
1980m2 | 1 | 0.014 | 1 |
1980m3 | 1 | 0.02 | 1 |
1980m4 | 1 | 0.003 | 1 |
1980m5 | 1 | -0.0012 | 1 |
1980m6 | 1 | -0.002 | 1 |
1980m7 | 1 | -0.01 | 1 |
1980m9 | 1 | 0.12 | 1 |
1980m10 | 1 | 0.019 | 1 |
1980m11 | 1 | 0.017 | 1 |
1980m12 | 1 | 0.005 | 1 |
1981m1 | 1 | 0.0032 | 1 |
1981m2 | 1 | 0.00684 | 1 |
1981m3 | 1 | 0.00239 | 1 |
1981m4 | 1 | 0.00005 | 1 |
1981m5 | 1 | -0.009 | 1 |
1981m6 | 1 | -0.0007 | 1 |
1981m7 | 1 | 0.005 | 1 |
1981m8 | 1 | -0.0003 | 1 |
1981m9 | 1 | 0.0078 | 1 |
1981m10 | 1 | 0.0039 | 1 |
1981m11 | 1 | -0.0083 | 1 |
1981m12 | 1 | -0.0099 | 1 |
1982m1 | 1 | -0.01 | 2 |
Comment