Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: saving enumerated file names at the end of a loop

From   Alan Riley <>
Subject   Re: st: saving enumerated file names at the end of a loop
Date   Sat, 24 Feb 2007 10:19:37 -0600

T.J. Volant ( asks about a file saving problem
in some code he wrote:
> I'm running a program through bunch of files(
> file1.dta, file2.dta, etc) I am opening them and would
> like to save them as replace. It opens fine, but
> saving doesn't work.
> My code:
> forv i=1(1)48 {
> use "C:\WINNT\Desktop\file`i'.dta"
> * body of the program *
> save "C:\WINNT\Desktop\file`i'.dta", replace
> clear
> }
> When it saves, it only saves, not file1.dta,
> etc. Why?

Some others have speculated that the problem may be due to
backslashes or due to the directory in which TJ is saving the
file.  From the code above, this is not the problem.  The
only time a backslash is interpreted in a special way by
Stata is when it immediately preceeds a local (`) or global ($)
macro character.

Something in the body of the loop that we cannot see must be
clearing local macro i.  This makes Stata see

    save "C:\WINNT\Desktop\file.dta", replace

rather than

    save "C:\WINNT\Desktop\file1.dta", replace

If TJ wishes to email, someone will help him
track down what is going wrong in his code.

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index