Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Why do `test' and a`test' make a difference?

From   Jeph Herrin <>
Subject   Re: st: Why do `test' and a`test' make a difference?
Date   Sun, 10 Feb 2013 22:10:25 -0500

I'd like a systematic account of how word lists are parsed. For instance, I have been scratching my head over the output of this:

local test "Jeph's Example"
local wordA `: word 1 of `test''
local wordB : word 1 of `test'
local wordC =`"`:word 1 of `test''"'+"[ ]"+`"`:word 2 of `test''"'
di "`wordA'"
di "`wordB'"
di "`wordC'"


On 2/10/2013 7:20 PM, Nick Cox wrote:
See also

for a systematic account.


On Sun, Feb 10, 2013 at 9:24 PM, Dirk Enzmann
<> wrote:
Thank you Nick, very helpful!

And thanks to Statalist as an institution to turn to when searches such as
-hsearch backslash-, -hsearch pathname-, -hsearch filename-, -search escape-
or the subject index of the manual(s) do not help. I suspected an issue with
escape characters, but didn't know where to look for help besides asking

With your help I could locate section 18.3.11 in [U] which explicitly warns
Windows users about not using backslashes in pathnames. However, I still
couldn't locate an explanation of the use of the backslash \ as an escape
character in the manuals.

To summarize: Whereas the use of a backslash results in

. global path = "d:\my folder\"
. local test = "pre_"
. di "${path}`test'my name.dta"
d:\my folder`test'my name.dta
. di "${path}a`test'my name.dta"
d:\my folder\apre_my name.dta

the clean way of using forward slashes, instead, results in

. global path = "d:/my folder/"
. local test = "pre_"
. di "${path}`test'my name.dta"
d:/my folder/pre_my name.dta
. di "${path}a`test'my name.dta"
d:/my folder/apre_my name.dta


In Stata backslashes have two roles

1. General: As an escape character.

2. Specific, for Windows users so inclined: As a separator within >

and single left quotation marks ` also have two roles

1. As introducing local macro references.

2. As literal characters, an interpretation you insist on with \`



is taken as a sign that for some reason for your own you are
protecting the ` of `test', which is why you put the \ in there.

So, don't do that. Use forward slashes for pathname separators, even
in Windows. This advice is spelled out in [U] and again in

SJ-8-3  pr0042  . . . . . . .  Stata tip 65: Beware the backstabbing >
         . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . > N.
J. Cox
         Q3/08   SJ 8(3):446--447                                 (no >
         tip to use forward slash instead of backslash for
         directory and file names


On Sun, Feb 10, 2013 at 1:18 PM, Dirk Enzmann

Why does the backslash as part of the global macro $path vanish (and

`test' is not evaluated as a local macro) when immediately combined with
the local macro `test', although it does not vanish (and the content of
`test' is displayed) when not immediately combined as shown in the two
variants of -di- in the example below?

* --- Stata example start: -----------

global path = "d:\my folder\"
local test = "pre_"
di "${path}`test'my name.dta"
di "${path}a`test'my name.dta"

* --- End Stata example. ------------

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index