Bookmark and Share

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: are Macro variable always possible ?


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: are Macro variable always possible ?
Date   Sun, 28 Aug 2011 19:47:42 +0100

Matthew is correct.

If you try to -display- your macro by using " " you just get another
version ot the same problem. There is an ambiguity between " as a
string delimiter and " as a a literal character. You need to use
compound double quotes again.

. di `"`filter'"'

By the way,

. macro list

gives a way of seeing macro definitions without encountering this problem.

In Stata, macros are not considered to be variables and so the
expression "macro variables" is best avoided. See e.g.

http://www.stata.com/statalist/archive/2008-08/msg01258.html

Nick

On Sun, Aug 28, 2011 at 7:36 PM, John Litfiba <[email protected]> wrote:
> Hello Matt,
>
> Thank you very much for your kind answer
> But... its doesnt seem to work, right ?
>
> If I call the macro I obtain the same error
>
> . display "`filter'"
> var1==unknown function hello"&var2==1&var3==43&var6=="helloagain"&!missing()
>
>
> On 28 August 2011 20:14, Matthew White <[email protected]> wrote:
>> Enclosing it in double quotes should do the trick:
>> local filter `"var1=="hello"&var2==1&var3==43&var6=="hello
>> again"&!missing(var34)"'
>>
>> Best,
>> Matt
>>
>> On Sun, Aug 28, 2011 at 5:52 PM, John Litfiba <[email protected]> wrote:
>>> Dear Statalist,
>>>
>>> I have a very simple question about macro variables:
>>>
>>> I would like to define a macro variable which stores a long sequence
>>> of data restrictions that I use after any IF qualifier when a function
>>> allows it ..
>>>
>>> For example instead of writing
>>>
>>>  regress Y X if var1=="hello"&var2==1&var3==43&var6=="hello
>>> again"&!missing(var34) ,
>>>
>>> I tried to define a macro as
>>>
>>>  local filter var1=="hello"&var2==1&var3==43&var6=="hello again"&!missing(var34)
>>>
>>> in order to simply write
>>>
>>> regress Y X if `filter'
>>>
>>> However it doent seem to work as Stata doesnt like at all the part
>>> var1=="hello" (because of the ""), causing an error in the
>>> interpretation...
>>>
>>> Has anyone an idea ?
>>>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index