I have a dataframe which looks like this
id year
1 2000
2 2000
1 2001
3 2001
4 2002
5 2002
6 2002
5 2003
6 2003
4 2004
5 2004
I want to progressively count how many consecutive years ids appear in my dataframe. In other words I want to get
id year count
1 2000 1
2 2000 1
1 2001 2
3 2001 1
4 2002 1
5 2002 1
6 2002 1
5 2003 2
6 2003 2
4 2004 1
5 2004 3
Do you have any suggestion? Many thanks, Marco