Hi everyone!

I am dealing with a worldwide data set on conflict events with an unbalanced panel structure, where I am given the variable "id", "year", as well as "region" and "location".

I want to create a binary variable "other_conflicts_region" that identifies whether there were other conflicts in the same region in the same year. I also want to create a binary variable "other_conflicts_world" that identifies whether there were any other conflicts in the world in the same year.

Here is a subset of my data:
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str8 id double year str8 region str28 location
"100_1945" 1945 "Asia"     "Vietnam"                     
"101_1945" 1945 "Asia"     "Indonesia"                   
"238_1945" 1945 "Europe"   "USSR"                        
"129_1946" 1946 "Americas" "Colombia"                    
"376_1946" 1946 "Europe"   "Estonia"                     
"380_1946" 1946 "Europe"   "Latvia"                      
"381_1946" 1946 "Europe"   "Lithuania"                   
"153_1946" 1946 "Africa"   "Nigeria"                     
"199_1946" 1946 "Africa"   "Eritrea"                     
"378_1946" 1946 "Asia"     "Iran"                        
"109_1946" 1946 "Asia"     "Palestine"                   
"425_1946" 1946 "Asia"     "China"                       
"100_1946" 1946 "Asia"     "Vietnam"                     
"91_1946"  1946 "Asia"     "Philippines"                 
"101_1946" 1946 "Asia"     "Indonesia"                   
"238_1946" 1946 "Europe"   "USSR"                        
"432_1946" 1946 "Americas" "Bolivia"                     
"371_1946" 1946 "Asia"     "Cambodia (Kampuchea)"        
"368_1946" 1946 "Asia"     "Princely State of Travencore"
"364_1946" 1946 "Asia"     "Laos"                        
"401_1946" 1946 "Europe"   "Greece"                      
"129_1947" 1947 "Americas" "Colombia"                    
"166_1947" 1947 "Americas" "Paraguay"
                                   
end
I suspect I need to build my code with by and sort, but I am pretty new to this, so I would really appreciate your help and thoughts to get me started!

Kind regards,
Birte
(Stata 17.0 SE)