Hello,
I have the following stylized dataset:
I want to achieve Var6.
Var 6 is a combination of the 5 names (Strings) in an alphabetical order.
I thought of something like:
egen var6 = concat(name1 name2 name3 name4 name5), punct(" ")
but it misses the alphabetical order.
I also though of
gen var6 = cond(nam1<name2, name1 + " " + name2, name2 + " " + name1) // and so on for all 5 names
but the condition would be inefficiently long (at least in my mind if I am correct)
Bests
Julian
I have the following stylized dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str12 name1 str11 name2 str12(name3 name4 name5) str61 var6 "Ami Tall" "Peter Brown" "Ben Williams" "Tim Small" "Marie Miller" "Ami Tall Ben Williams Marie Miller Peter Brown Tim Small" "Peter Brown" "Ami Tall" "Ben Williams" "Marie Miller" "Tim Small" "Ami Tall Ben Williams Marie Miller Peter Brown Tim Small" "Marie Miller" "Ami Tall" "Ben Williams" "Peter Miller" "Samuel Brown" "Ami Tall Ben Williams Marie Miller Peter Miller Samuel Brown" end
I want to achieve Var6.
Var 6 is a combination of the 5 names (Strings) in an alphabetical order.
I thought of something like:
egen var6 = concat(name1 name2 name3 name4 name5), punct(" ")
but it misses the alphabetical order.
I also though of
gen var6 = cond(nam1<name2, name1 + " " + name2, name2 + " " + name1) // and so on for all 5 names
but the condition would be inefficiently long (at least in my mind if I am correct)
Bests
Julian
Comment