Jun 19
Get list of unique variable values in Stata
UPDATE:
A better solution to the problem posed below is:
levelsof country, local(levels)
foreach cnt of local levels {
More information available from the Stata FAQ.
Suppose you have a database of countries over time in the long format and you want a simple list of the countries. If that dataset is open, simply run the following:
preserve
by country, sort: gen nvals = _n
keep if nvals == 1
keep country
save country_list, replace
restore
