According to us house election data a single county for a specific state belongs to multiple congressional districts. However, based on the total geographical area I can match unique county to a specific district for that state.

In the following data nhgisnam means the name of the county , district means Congressional district , cnty_area means the total geographical area of that county and cnty_part_area means the portion of total area of that county belonging to that particular congressional district. For example : In th first line for Autauga county the cnty_part_area's value is 1564828723. That means in district 2 Autauga county's total area is 1564828723 - out of its total area (cnty_area) of 1565529773. Autauga county also belong to district 2, district 7 and district 6 of state 1. But, the highestr portion of it's area belong to district 2 which I can figure out from that cnty_part_area variable.

Can anyone kindly guide me how I can code the data so that for each county in a particular state I can keep the observation where each county is assigned to a single district in that state based on the highest value of cnty_part_area variable for that specific county ??

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str36 nhgisnam str14 statenam byte(cd_statefip district) float county double(cnty_area cnty_part_area)
"Autauga"       "Alabama" 1 2 1001 1565529773  1564828723
"Autauga"       "Alabama" 1 6 1001 1565529773 272866.6476
"Autauga"       "Alabama" 1 7 1001 1565529773 428181.5623
"Baldwin"       "Alabama" 1 1 1003 4232265763  4228366412
"Baldwin"       "Alabama" 1 7 1003 4232265763 149732.2219
"Barbour"       "Alabama" 1 2 1005 2342716428  2341574170
"Barbour"       "Alabama" 1 3 1005 2342716428 601774.0707
"Bibb"          "Alabama" 1 6 1007 1621774445  1621293818
"Bibb"          "Alabama" 1 7 1007 1621774445 480626.7196
"Alameda"      "California" 6  9 6001  1928023778 347196605.8
"Alameda"      "California" 6 10 6001  1928023778 350508415.5
"Alameda"      "California" 6 11 6001  1928023778 654388620.1
"Alameda"      "California" 6 13 6001  1928023778 571141686.4
"Alameda"      "California" 6 15 6001  1928023778  77415.0506
"Alpine"       "California" 6  3 6003  1924880954  1923718768
"Alpine"       "California" 6  4 6003  1924880954 194564.3245
"Alpine"       "California" 6 19 6003  1924880954 163767.2729
"Alpine"       "California" 6 25 6003  1924880954 326582.7162
"Amador"       "California" 6  3 6005  1566159667  1565521028
"Amador"       "California" 6  4 6005  1566159667 637209.1726
"Amador"       "California" 6 11 6005  1566159667 1425.507371
"Glenn"        "California" 6  1 6021  3437311730 146543.9293
"Glenn"        "California" 6  2 6021  3437311730  3437165187
"Humboldt"     "California" 6  1 6023  9286259251  9282075925
"Humboldt"     "California" 6  2 6023  9286259251 589746.8231
"Los Angeles"  "California" 6 22 6037 10591484333  1402787367
"Los Angeles"  "California" 6 24 6037 10591484333 350751.8175
"Los Angeles"  "California" 6 25 6037 10591484333  4108619373
"Los Angeles"  "California" 6 26 6037 10591484333  1272584266
"Los Angeles"  "California" 6 27 6037 10591484333 392578311.2
"Los Angeles"  "California" 6 28 6037 10591484333 201732469.2
"Los Angeles"  "California" 6 29 6037 10591484333 262922748.4
"Los Angeles"  "California" 6 30 6037 10591484333 742182418.1
end