Statalist


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

Re: st: RE: -replace- should not be use with temporary files (was:Comparing datasets)


From   Kevin Crow <kcrow@stata.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: -replace- should not be use with temporary files (was:Comparing datasets)
Date   Thu, 18 Sep 2008 12:00:11 -0500

On Thu, 18 Sep 2008, Nick Cox wrote:

This came up on the list a while back.

Suppose you mistype the local macro reference. Say you mean to type

save `myfile', replace

but you have a minute brainstorm and you type `myfil'. Further suppose
that local macro `myfil' is not defined. Then Stata sees

save, replace

which to Stata is perfectly legal and intelligible. Stata will overwrite
the original data file, which is not what you intended at all. Of
course, typos here and there can have all sorts of consequences, all of
which are strictly your fault, but this one could be catastrophic if
what you had in memory was only a small part of the data or nothing to
do with the dataset you last read in.

There may be other reasons for not doing this, but that's one.

Nick

--------------------------------------------------------------------------------

I was able to track down the email that was sent to Steven via our database and
Nick is exactly right on what happened. What we told Steven was

"The -replace- option shouldn't be needed when using temporary files
because they are freshly created each time the procedure is run."

For this particular do-file the advice was correct because a temporary file was not getting created so the command -save `no_temp_file', replace- could be replacing a file on disk, not a temporary file. In short, it is ok to use -replace- with temporary files but it could be dangerous.

Kevin Crow
StataCorp




This came up on the list a while back.
Suppose you mistype the local macro reference. Say you mean to type
save `myfile', replace
but you have a minute brainstorm and you type `myfil'. Further suppose
that local macro `myfil' is not defined. Then Stata sees
save, replace

which to Stata is perfectly legal and intelligible. Stata will overwrite
the original data file, which is not what you intended at all. Of
course, typos here and there can have all sorts of consequences, all of
which are strictly your fault, but this one could be catastrophic if
what you had in memory was only a small part of the data or nothing to
do with the dataset you last read in.
There may be other reasons for not doing this, but that's one.
Nick n.j.cox@durham.ac.uk
Joseph Coveney

Steven Samuels wrote (excerpted):

. . . Technical support told me that "replace" should not be used when
saving temporary files.

------------------------------------------------------------------------
--------

This is news to me. I use -replace- all of the time with temporary
files.
What did StataCorp technical support say was the matter with using
-save . . . , replace- with temporary files?


*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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