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
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Jann, Ben
> Sent: 03 March 2004 10:47
> To: [email protected]
> 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/