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

Re: st: parmby if=exp for strings


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: parmby if=exp for strings
Date   Wed, 14 Jul 2004 19:09:04 +0100

At 18:41 14/07/2004, Douglas wrote:
Hi,

I am performing a series of parmby's for stcox analyses.  In my hands, I
have found that _if_ only accepts numeric expressions:

stcox var1 var2 if inlist(var3, "string1", "string2")

works just fine, but

parmby "stcox var1 var2 if inlist(var3, "string1", "string2")",
saving(parms1.dta)

does not work, I get the following error message:

varlist not allowed
r(101);

However I can get around this problem by converting the string variable to a
numeric one:

encode var3, gen(var3_nu)
parmby "stcox var1 var2 if inlist(var3_nu, 1, 2)", label eform
saving(parms1.dta)

works just fine

Is there a general rule about the use of =exp for strings that I am not
aware of?
Your mistake here is to have strings delimited by simple quotes inside strings delimited by simple quotes. If your -parmby- command argument is instead delimited by compound quotes, as in

parmby `"stcox var1 var2 if inlist(var3, "string1", "string2")"', saving(parms1.dta)

then -parmby- should work, because the strings "string1" and "string2" are delimited by simple quotes, and the string argument

`"stcox var1 var2 if inlist(var3, "string1", "string2")"'

is delimited by compound quotes. (Let me know if it doesn't work.)

Compound quotes can surround strings containing strings delimited by simple quotes or other strings delimited by compound quotes, but simple quotes cannot surround strings containing strings delimited by simple quotes. This is because left compound quotes can be distinguished from right compound quotes, but simple quotes come in only one type, which can be either left or right.

To find out more about simple or compound quotes, see the User's Guide under -[U] 21.3.5 Double quotes-.

I hope this helps.

Roger













--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

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