Typo removed
Here is the more general example code in one for copiers and pasters.
To apply to a different example:
1. Change -myvar- to whatever is appropriate.
2. Check that variable names -distinct- and -same- are not in use.
3. Change the separator from , if needed.
-----------------------------------------------------------
split myvar, p(,)
replace myvar1 = trim(myvar1)
gen distinct = myvar1
gen byte same = 0
local nvars : word count `r(varlist)'
qui forval i = 2/`nvars' {
replace myvar`i' = trim(myvar`i')
replace same = 0
local prev = `i' - 1
forval j = 1/`prev' {
replace same = 1 if myvar`i' == myvar`j'
}
replace distinct = distinct + "," + myvar`i' ///
if !same & myvar`i' != ""
}
-----------------------------------------------------------
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/