On Mar 8, 2005, at 12:54 AM, Philip Greenwood wrote:
. local foo "a_great_big_fish"
. save "data\`foo'.dta"
file data`foo'.dta saved
I expected `foo' to evaluate to "a_great_big_fish" in the save command.
Using a double slash fixes the problem ( i.e. -save "data\\`foo'.dta"-
).
IIRC, Stata -- like many other programming languages -- interprets the
\ as an "escape" character, meaning: "rather than interpret the next
character in a programming context, interpret it literally." That is,
by placing \` in your command, you told Stata, "I really want a ` in
the file name, rather than use the ` to signify the beginning of a
macro substitution."
By using \\, you "escaped the escape" -- you told Stata: \ =
"interpret the next character literally" + \ = "as a backslash", which
placed the backslash in the file name. Notice that the second \ is
interpreted literally instead of as an escape character, so the ` began
the macro substitution as you expected.
IIFRC, Stata recognizes / as the "universal filesystem separator";
thus you could have written -save "data/`foo'.dta"- (notice: slash in
other direction), and it would have worked as expected.
(Disclaimer: I don't do Windows, so I cannot test the above. I also
don't have the manual in front of me, but I'm sure someone will correct
any errors above. Like confusing which of \ and / is called the
"backslash" -- I do that all the time....) HTH.
-- Mike
*
* 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/