the -\`- tells Stata not to interpret `file' as a macro, hence instead you need:
inputst d:\Data\CGSData\\`file'.wb2
(And similarly for the following line)
David
[email protected]
-----Original Message-----
From: Devra Golbe [mailto:[email protected]]
Sent: 22 July 2004 16:42
To: [email protected]
Subject: Re: st: RE: foreach syntax
Thanks, but that was just an unfortunate typo in my e-mail. Here's exactly
the code which failed. Note the input line fails before I even get to the
save. I've just checked (again) that the files are where I think they are
(ie, d:\Data\CGSData\owner00r.wb2 does exist.) Sorry for not being clear
the first time.
******
inputst d:\Data\CGSData\owner00r.wb2
. clear
. local files "owner00r owner99r owner93r"
. foreach file of local files {
2. clear
3. inputst d:\Data\CGSData\`file'.wb2
4. capture save d:\Data\CGSData\`file', replace
5. }
Stat/Transfer did not run successfully
file not found
r(601);
******
. inputst d:\Data\CGSData\owner00r.wb2
. clear
. local files "owner00r owner99r owner93r"
. foreach file of local files {
2. clear
3. inputst "d:\Data\CGSData\`file'.wb2"
4. capture save "d:\Data\CGSData\`file'", replace
5. }
Stat/Transfer did not run successfully
file not found
r(601);
end of do-file
r(601);
At 11:26 AM 7/22/2004, you wrote:
>Try
>
>capture save "d:\Data\CGSData\`file'", replace
>
>instead of
>
>capture save "d:\Data\CGSData\`file''", replace
>
>Gabi
>
>-----Original Message-----
>From: Devra Golbe [mailto:[email protected]]
>Sent: Thursday, July 22, 2004 11:22 AM
>To: [email protected]
>Subject: st: foreach syntax
>
>
>hI,
>
>I am trying to run a simple foreach loop, but my code is clearly not
>being parsed correctly, because the code below results in a "file not
>found" error, (as does the same code without the double quotes inside the
>foreach loop.) I've looked at the programming section of the User guide,
>but I can't find the source of my error, which is undoubtedly very
>simple. Can someone point me in the right direction?
>
>Thanks,
>Devra
>
>
>****
>local files "owner00r owner99r owner93r"
>foreach file of local files {
>clear
>inputst "d:\Data\CGSData\`file'.wb2"
>capture save "d:\Data\CGSData\`file''", replace
>}
>
>*****
>
>_
*
* 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/
*
* 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/