# Conflict duration: total number of active conflict years

conflictDuration <- function(x) {
  #currentYear <- as.numeric(x[c("year")])
  conflictID <- as.numeric(x[c("conflictid")])
  #startYear <- as.numeric(unique(Master[Master$conflictid == conflictID,]$year[1])) # this does not take into account that there are interim years!
  # thus, just assign the total number of active conflict years (as do Cohen 2013 and Cohen/Nordas 2015)
  duration <- as.numeric(length(unique(Master[Master$conflictid == conflictID & Master$conflictyear==1,]$year)))
  #duration <- as.numeric(currentYear - startYear)
  return(duration)
}

Master$duration <- 0
Master[Master$conflictyear==1,]$duration <- apply(Master[Master$conflictyear==1,], 1, conflictDuration)
