Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Levelsof for more than one Variable
Nick Cox <firstname.lastname@example.org>
Re: st: Levelsof for more than one Variable
Mon, 21 Jan 2013 16:34:14 +0000
I think you will need to use compound double quotes.
Compare the results of
sysuse auto, clear
levelsof make in 1/10, local(levels)
On Mon, Jan 21, 2013 at 4:22 PM, Roberto Liebscher
> Thanks Maarten for the kind help. However I still haven't managed to get the
> code working.
> Like you said I typed
> levelsof var1, local(loc1)
> levelsof var2, local(loc2)
> // stack the macros
> // NOTICE: no "=" sign
> local loc "`loc1' `loc2'"
> // get rid of the duplicates
> local loc : list uniq loc
> But when I type
> display "`loc'"
> to get the final list an error message is prompted saying
> `ABN not found
> where ABN is part of the first element of loc1 ("ABN Amro Bank"). Is it a
> problem that my elements in the list contain blank spaces? Is there a way
> around? I already tried the same code with the blank space being replaced by
> "_" (using subinstr). Following this another error message pops up saying
> "`unknown function ABN_AMRO_Bank_N.V."' `"BNP_Paribas"'" . I do not know
> what is wrong here. Any help is highly appreciated.
> Roberto Liebscher
> Catholic University of Eichstaett-Ingolstadt
> Department of Business Administration
> Chair of Banking and Finance
> Auf der Schanz 49
> D-85049 Ingolstadt
> Am 21.01.2013 15:52, schrieb Nick Cox:
>> As a kind of meta-comment I recommend against the use of "unique" in
>> this context.
>> "Unique" means occurring once only. It's a good word, and best left to
>> mean that, as your school teachers may have urged. For example,
>> "StataCorp is a unique company". Very true (if also trite).
>> Naturally, some might want to start the age-old discussion of whether
>> usage sanctifies abuse of etymology. But even descriptively-inclined
>> dictionaries don't seem to sanction the sense of this word "unique" as
>> meaning "distinct", which I suggest is a much better word than
>> "unique" for this purpose.
>> My guess is that the popularity of "unique" in this meaning stems
>> partly from Unix utilities such as -uniq-, which removes copies from a
>> list and leaves one and one copy of each distinct item as a result.
>> a a a b b c
>> would be reduced to
>> a b c
>> by such utilities.
>> Here uniqueness defines each item in the result, not each item in the
>> argument. My guess is that many software developers encountered such
>> utilities such as -uniq- in their youth and that had a greater
>> influence on them than their English dictionaries (if they had one) or
>> their English teachers (if they paid them much attention).
>> I have a long-term plan to persuade StataCorp of this too. See also
>> SJ-8-4 dm0042 . . . . . . . . . . . . Speaking Stata: Distinct
>> (help distinct if installed) . . . . . . N. J. Cox and G. M.
>> Q4/08 SJ 8(4):557--568
>> shows how to answer questions about distinct observations
>> from first principles; provides a convenience command
>> I can't speak authoritatively on languages other than English -- "not
>> even", some might think -- so not mentioning them means only that.
>> On Mon, Jan 21, 2013 at 2:30 PM, Maarten Buis <email@example.com>
>>> // collect the values
>>> levelsof var1, locals(loc1)
>>> levelsof var2, locals(loc2)
>>> // stack the macros
>>> // NOTICE: no "=" sign
>>> local loc "`loc1' `loc2'"
>>> // get rid of the duplicates
>>> local loc : list uniq loc
>>> For more see: -help extended_fcn- and especially -help macrolists-
>>> Hope this helps,
>>> On Mon, Jan 21, 2013 at 3:02 PM, Roberto Liebscher
>>> <firstname.lastname@example.org> wrote:
>>>> I have two variables both containing string values. I would like to get
>>>> unique values (not the number of unique values) from these two variables
>>>> For example if I enter
>>>> levelsof var1, locals(loc1)
>>>> levelsof var2, locals(loc2)
>>>> I obtain all unique values of var1 and all unique values of var2. But at
>>>> end I would like to have one local containing only unique values in loc1
>>>> Is there anyone who can help me with this?
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/faqs/resources/statalist-faq/
>> * http://www.ats.ucla.edu/stat/stata/
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
* For searches and help try: