NBER Test
>
> I'd like to save typing and clean up a program by
> using
> a local variable with conditions that evaluate strings
> like below:
>
> local 1 "whatever"
> local if "``1' == "first thing" | `1' == "second
> thing"'"
> if `if' { ...
>
> only I can't get the quotes or compound quotes in my
> `if' declaration to resolve quite right.
Like David Moore, I am a little unclear about
what the problem is, although my guess differs
from his. But if you are going
to compare a macro with a literal string
you _must_ place the macro name in quotes:
if "`1'" == "first thing" | "`1'" == "second thing"
It could well be that you should just evaluate
your condition as true or false as soon as
you have the information:
local OK = "`1'" == "first thing" | "`1'" == "second thing"
if `OK' {
...
}
As a matter of style alone, I would not use
the local macroname -if- for something which
didn't actually contain the literal "if"
followed by a true-or-false condition. This
is recognition of how -syntax- behaves
and to make programs easier to read.
Nick
[email protected]
*
* 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/