Hello,

I have a data which shows distance between all counties from another county. This includes all the counties from census. However, my aim is to find the distance between counties only where both counties ( county1 and county2 ) belong to the same state. May anyone kindly guide me how I can do it? The county1 and county2 variable are constructed where the first two digits are the indicator of state. So, if I can match it , then I'll be able to find my desired outcome. But, I don't know how I can do it.

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str5 county1 double mi_to_county str5 county2
"01001" 22.462994302208628 "01021"
"01001" 26.844686566998814 "01085"
"01001"  29.51758494098288 "01051"
"01001" 30.776370841805658 "01047"
"01001" 34.493442726438765 "01101"
"01001"  35.89275856373744 "01037"
"01001"  38.46086856066846 "01105"
"01001"  43.40325272873116 "01007"
"01001"  50.23794560165572 "01117"
"01001"  53.85235728142641 "01131"
"01001"  54.07279881059125 "01123"
"01001" 54.262868563770404 "01013"
"01001"  56.42751293745245 "01087"
"01001"  58.69133403697369 "01041"
"01001" 101.67804794852763 "13145"
"01001" 102.08414383983288 "01029"
"01001" 102.46631237320776 "01053"
"01001" 103.10412245380951 "13215"
"01001"  104.5617424700897 "01057"
"01001"   106.367621532817 "13239"
"01001"  141.6540499512556 "28095"
"01001" 143.09524309514657 "28105"
"01001" 143.14762563679008 "01079"
"01001" 143.92170699307306 "28159"
"01001" 144.50693930791743 "28101"
end