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

st: RE: Using the -if- qualifier with a string variable


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Using the -if- qualifier with a string variable
Date   Sun, 3 Apr 2005 16:28:19 +0100

Yes, it can. The problem here lies in your use of 
syntax indicating something different from what
you want. Or, you want Stata to guess what you 
mean, but Stata can only go on what you actually say. 

In your expression 

facility==bir 

you are expecting Stata to know somehow that you intend

facility 

be treated as the name of a variable but 

bir 

to be treated as a literal string value. 

However, as you are being told, it is interpreting 
the latter as the name of a string variable, 
with the problem in this case that no 
such variable exists. 

You need to use " " to signal a particular
string value. 

.. if facility == "bir" 

Note also that while most Stata users would 
write something like that, there is 
no reason why you should not write instead 

... if "bir" == facility

Otherwise put, Stata attaches no 
significance to the order of operands
in an assertion of equality -- just in 
case you are thinking somehow that the 
order of mention is important. 

Similarly, we often say things like 

... if x == 2 

but that is just a carry-over from 
mathematical convention leading 
us to say something like 

... if x = 2

rather than 

... if 2 = x. 

Nick 
[email protected] 

louis boakye-yiadom

> Can the -if- qualifier be used with a string variable? If so, 
> how is it 
> done? I gave the following command, and had the shown result:
> . keep if facility==bir
> bir not found
> r(111);
> 
> "facility" is a string variable and "bir" is one of the 
> values "facility" 
> takes. Thank you.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index