How to extract unique strings from a macro?
问题 I'm trying to automate a reshape using Stata. I have a series of variables measured yearly. They are all named varname_yy , where yy is a number referring to the year of measurement. I managed to extract all the stubs varname_ from the variables and to put them into a macro using the following code: local stubs foreach var of varlist `myvars' { local stub = substr("`var'",1,length("`var'") - 2) local stubs `stubs' `stub' } The problem is that I end up with many repeated stubs in the stubs