I have a dataset which contains information on the number of fatalities for state-based conflicts (ged_sb_best_sum_nokgi) for different coutries and for the years 1989-2021.
The dataset is called conflict and looks something like this:
isoname year ged_sb_best_sum_nokgi
Afghanistan 1989 5174
Afghanistan 1990 5143
Afghanistan 1991 763
Afghanistan 1992 15
...
Afghanistan 2021 34
...
Zimbabwe 1989 13
Zimbabwe 1990 57
Zimbabwe 1991 124
...
Zimbabwe 2021 5
I have created a dummy equal to 1 if the number of fatalities is => 25, as so:
conflict <- conflict %>%
group_by(isoname)%>%
mutate(conf_incidence_sb = ifelse(ged_sb_best_sum_nokgi >= 25,1,0))
And I get the variable conf_incidence_sb, which takes the following values:
isoname year ged_sb_best_sum_nokgi conf_incidence_sb
Afghanistan 1989 5174 1
Afghanistan 1990 5143 1
Afghanistan 1991 763 1
Afghanistan 1992 15 0
...
Afghanistan 2021 34 1
...
Zimbabwe 1989 13 0
Zimbabwe 1990 57 1
Zimbabwe 1991 124 1
...
Zimbabwe 2021 5 0
The next thing I would like to do is create a variable called conflict_duration_sb, which counts the number of years the conflict has been ongoing since it started. The dataset should look something like this:
isoname year ged_sb_best_sum_nokgi conf_incidence_sb conf_duration_sb
Afghanistan 1989 5174 1 1
Afghanistan 1990 5143 1 2
Afghanistan 1991 763 1 3
Afghanistan 1992 15 0 0
...
Afghanistan 2021 34 1 1
...
Zimbabwe 1989 13 0 0
Zimbabwe 1990 57 1 1
Zimbabwe 1991 124 1 2
...
Zimbabwe 2021 5 0 0