I have a panel dataset of countries for which in each year (from 1980 to 2020) I have a dummy on whether there was a conflict in that particular country and another dummy on whether there was a coup. Moreover, I have for each country the ID of the neighboring countries, which are the same in each year. What I need to do in R is to create a new dummy "Conflict_Coup_Neighbors" which takes value 1 if in a particular year there was a conflict or a coup in at least one of the neighbor countries. I guess it should be a loop that checks for each country, for each year and for each neighbor whether the dummy conflict or coup of the neighbor are =1 but I can't understand how to set it up. Below I leave a snapshot of the dataset Dateset
Asked
Active
Viewed 19 times
-1
-
1Welcome to SO, Emiliano! Please do not post (only) an image of code/data/errors: it breaks screen-readers and it cannot be copied or searched (ref: https://meta.stackoverflow.com/a/285557 and https://xkcd.com/2116/). Please include the code, console output, or data (e.g., `data.frame(...)` or the output from `dput(head(x))`) directly. Please see https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info for good discussions on reproducibility in questions. Thank you! – r2evans May 11 '22 at 13:09