Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: ... and you can quote me


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: ... and you can quote me
Date   Thu, 25 Sep 2003 11:09:42 +0100

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 
n.j.cox@durham.ac.uk 
 

*
*   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/



© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index