Hi,

I have a dataset that looks like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str7 country1 str11 country2 str4 group
"China"   "Philippines" "68a"
"China"   "Thailand"    "68a"
"Bahamas" "Jamaica"     "176a"
"Bahamas" "Grenada"     "176a"
end
I need to transform the above dataset into like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str11(country1 country2) str4 group
"China"       "Philippines" "68a"
"China"       "Thailand"    "68a"
"Philippines" "China"       "68a"
"Philippines" "Thailand"    "68a"
"Thailand"    "China"       "68a"
"Thailand"    "Philippines" "68a"
"Bahamas"     "Jamaica"     "176a"
"Bahamas "    "Grenada"     "176a"
"Jamaica"     "Bahamas"     "176a"
"Jamaica"     "Grenada"     "176a"
"Grenada"     "Bahamas"     "176a"
"Grenada"     "Jamaica"     "176a"
end
I tried my best to follow the Stata code in this article: https://www.stata.com/support/faqs/d...-to-all-pairs/. However, I ended up with a dataset that looks like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str7 country1 str11 countr2 str4 group
"China"   "Philippines" "68a"
"China"   "Philippines" "68a"
"China"   "Thailand"    "68a"
"China"   "Thailand"    "68a"
"Bahamas" "Jamaica"     "176a"
"Bahamas" "Jamaica"     "176a"
"Bahamas" "Grenada"     "176a"
"Bahamas" "Grenada"     "176a"
end

I'm not sure what I'm doing wrong. Thanks in advance for your help!

This question is also posted here: https://stackoverflow.com/questions/...ach-group-in-s

Best,

Dotty