Hello all,
I'm trying to calculate the longest period of drought in the five years before a census. My data is available by state and by month. I have a binary variable called "drought" that is equal to 1 when SPI (standard precipitation index) values indicate a drought and 0 otherwise. For simplicity, I present a subset of data for 1 state only. The variable longest_drought is what I want to obtain.
As you can see, the longest drought period is from 10/2016 to 3/2017 for a period of 6 months. I require a variable that is equal to 6 for all the observations listed here.
Thank you.
I'm trying to calculate the longest period of drought in the five years before a census. My data is available by state and by month. I have a binary variable called "drought" that is equal to 1 when SPI (standard precipitation index) values indicate a drought and 0 otherwise. For simplicity, I present a subset of data for 1 state only. The variable longest_drought is what I want to obtain.
state | month | year | drought | longest_drought |
1 | 9 | 2015 | 0 | 6 |
1 | 10 | 2015 | 0 | 6 |
1 | 11 | 2015 | 1 | 6 |
1 | 12 | 2015 | 1 | 6 |
1 | 1 | 2016 | 1 | 6 |
1 | 2 | 2016 | 0 | 6 |
1 | 3 | 2016 | 1 | 6 |
1 | 4 | 2016 | 0 | 6 |
1 | 5 | 2016 | 0 | 6 |
1 | 6 | 2016 | 0 | 6 |
1 | 7 | 2016 | 0 | 6 |
1 | 8 | 2016 | 0 | 6 |
1 | 9 | 2016 | 0 | 6 |
1 | 10 | 2016 | 1 | 6 |
1 | 11 | 2016 | 1 | 6 |
1 | 12 | 2016 | 1 | 6 |
1 | 1 | 2017 | 1 | 6 |
1 | 2 | 2017 | 1 | 6 |
1 | 3 | 2017 | 1 | 6 |
1 | 4 | 2017 | 0 | 6 |
As you can see, the longest drought period is from 10/2016 to 3/2017 for a period of 6 months. I require a variable that is equal to 6 for all the observations listed here.
Thank you.
Comment