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

st: RE: Problems with strings starting with an apostrophe


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Problems with strings starting with an apostrophe
Date   Wed, 3 Mar 2004 11:12:59 -0000

I have not checked all your examples, but 
I can suggest lines of attack. 

First line of attack: try "\'", not "'". 

Second, reach for SMCL. 

. di "{c 39}whatever"

Third, use -char()-. 

. di "`=char(39)'whatever"

Agreed: these are all more or less painful. 
In a program or do file, I'd put ` and then 
do a conditional search and replace with 
a decent text editor. 

Nick 
n.j.cox@durham.ac.uk 

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Jann, Ben
> Sent: 03 March 2004 10:47
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Problems with strings starting with an apostrophe
> 
> 
> Dear colleagues,
> 
> strings starting with an apostrophe (') sometimes cause weired errors
> even if embraced in compound double quotes. For example
> 
>  . di 1 + match("",`"'whatever"')
> 
> produces an error, while
> 
>  . di match("",`"'whatever"') + 1
> 
> or
> 
>  . di 1 + match("","'whatever")
> 
> does not. Even odder:
> 
>  . lab def x 1 `"'whatever"' /*
>     */ 2 whatever
> 
> produces an error, while
> 
>  . lab def x 1 `"'whatever"' 2 whatever
> 
> works fine. Similarly ("s" being a string variable):
> 
>  . gen x = `"'whatever"'==s
> 
> is ok, but not
> 
>  . gen x= s==`"'whatever"'
> 
> This is very anoying because it makes it hard to write programs that
> work correctly. 
> 
> Does anyone know a "really" save way to treat strings?

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