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

Re: st: I'll never understand quotes


From   Ernest Berkhout <[email protected]>
To   [email protected]
Subject   Re: st: I'll never understand quotes
Date   Wed, 18 Jun 2003 11:25:20 +0200

At 23:09 17-6-2003, you wrote:
Hello - could someone please explain why statement #3 below fails if I put
double quotes around `sdir', but statement #2 needs to have double quotes?

1.      args gog sdir
2.      gen str5 sdir = "`sdir'"
3.      save gait_`gog'_`sdir', replace   (works)
3.      save gait_`gog'_"`sdir'", replace   (fails)
Lets take the danger of being only 99,9% correct and explain the main concept of it:

Your (single) macro quotes are needed to specify that whatever is in the local macro sdir is to be inserted at that point. If that local macro would contain the five characters abcde, things work out as follows.

In #2 you are specifiyng the *contents* of a new string *variable*. That always needs double quotes in normal syntax (I mean without the local macro's), like in <gen str5 sdir="abcde"> . The command <gen str5 sdir=abcde> wouldn't work at the command line either.

In #4 you are specifiyng a part of a filename, which -apart from the single macroquotes- does not need any double quotes in normal syntax, like in <save filename_alan_abcde, replace>.
At the commandline, <save filename_alan_"abcde", replace> would fail , and that is exactly how Stata translates your code. It fails because the character " is not allowed in any filename.

Ernest Berkhout
SEO Amsterdam Economics
University of Amsterdam

Room 3.08
Roetersstraat 29
1018 WB Amsterdam
The Netherlands

tel.:+ 31 20 525 1657
fax:+ 31 20 525 1686
http://www.seo.nl
===========================
A statistician: someone who insists
on being certain about uncertainty
===========================

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