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 <ariley@stata.com>
To   statalist@hsphsun2.harvard.edu
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 (tjvolant@yahoo.com) 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 file.data, 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 tech-support@stata.com, someone will help him
track down what is going wrong in his code.


Alan
(ariley@stata.com)
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index