Hi. I have a dataset of the form:
I want to create a new variablewhich adds up the road investmet between elections for every election year ("new var" in the table is how it should look like). However, I am not sure how to tell stata to only add up the spending since the last election year. I was wondering if someone knows how to do this?
Thank you very much!
| Country | year | road investment (m) | election | new_var |
| UK | 2010 | 5 | No | . |
| UK | 2011 | 4 | Yes | 9 |
| UK | 2012 | 9 | No | . |
| UK | 2013 | 2 | No | . |
| UK | 2014 | 5 | No | . |
| UK | 2015 | 7 | Yes | 23 |
| France | 2010 | 6 | No | . |
| France | 2011 | 5 | Yes | 11 |
| France | 2012 | 4 | No | . |
| France | 2013 | 6 | No | . |
| France | 2014 | 9 | Yes | 19 |
I want to create a new variablewhich adds up the road investmet between elections for every election year ("new var" in the table is how it should look like). However, I am not sure how to tell stata to only add up the spending since the last election year. I was wondering if someone knows how to do this?
Thank you very much!

Comment