Dear All, I have this data set
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input id str10 start str9 end str10 name
1 "2012-02" "2017-02" "A" 
1 "2017-03" "2017-10" "B"  
1 "2017-11" "2018-01" "C"
1 "2018-02" "2019-12" "D"   
1 "2020-01" "2020-12" "E"
2 "2013-08" "2015-08" "H" 
2 "2015-09" "2017-04" "I"  
2 "2017-05" "2019-07" "J"   
2 "2019-08" "2020-12" "K"
end
For each id and each year, I'd like to have a "name" in that cell. The basic criterion is that whoever serves the most time in the year is the one to keep.

The desired outcome is something like:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input id str10 start str9 end str10 name
1 2012 "A" 
1 2013 "A"  
1 2014 "A"
1 2015 "A"   
1 2016 "A"
1 2017 "B" 
1 2018 "D"   
1 2019 "D"
1 2020 "E"
2 2013 "H"  
2 2014 "H"
2 2015 "H"   
2 2016 "I"
2 2017 "J" 
2 2018 "J"   
2 2019 "J"
2 2020 "K"
end
Any suggestions are highly appreciated.