I have a panel data set of unemployment numbers over time for a series of countries. I have generated a variable that is equal to 1 if the unemployment rate is above 20% and I want to count the consecutive years that unemployment is above that rate. Some countries drop out of the data for some years as there were no events that year but i would like the count to include the missing year if possible I included an example of this. I have been able to create a straight sum of the highunemp variable for each country but not the consecutive years that I need. Here is an example of my data:

```
Country|Year |Unemprat| highunemp
-------|-----|--------|-------
      1| 2001| 15     |0
      2| 2001| 25     |1
      3| 2001| 40     |1
      1| 2002| 20     |1
      2| 2002| 25     |1
      3| 2002| 32     |1
      4| 2002| 8      |0
      1| 2003| 14     |0
      3| 2003| 22     |1
      4| 2003| 26     |1
      1| 2004| 23     |1
      2| 2004| 25     |1
      3| 2004| 10     |0
      4| 2004| 14     |0

```

Im looking for a dataset like this with the added variable for consecutive years

```
Country|Year |Unemprat| highunemp | conshigh
-------|-----|--------|-----------|---------
      1| 2001| 15     |0          |0
      2| 2001| 25     |1          |1
      3| 2001| 40     |1          |1
      1| 2002| 20     |1          |1
      2| 2002| 25     |1          |2
      3| 2002| 32     |1          |2
      4| 2002| 8      |0          |0
      1| 2003| 14     |0          |0
      3| 2003| 22     |1          |3
      4| 2003| 26     |1          |1
      1| 2004| 23     |1          |1
      2| 2004| 25     |1          |4
      3| 2004| 10     |0          |0
      4| 2004| 14     |0          |0

```

Ideally I am hoping to do this in Stata as that is where I have been working with my data currently but I can also work with R.