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

Re: st: Re: Generating tempfiles within a program for later use

From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: Re: Generating tempfiles within a program for later use
Date   Tue, 8 Jan 2008 08:20:29 -0500

David Kantor and P. Wilner Jeanty:
Beth wrote me offlist to say all is well now, so I suspect my example
clarified something.  However, there seems to be lingering confusion.
P. Wilner Jeanty claims that in his first example, a tempfile
"vanishes itself" at the end of execution.  I suspect P. Wilner Jeanty
is copying his code into a do-file and running it, rather than copying
the code directly to the Command window.  When a do-file finishes
executing, locals defined in that file are released from memory, and
tempfiles are erased, much as happens when a -program- stops
executing.  So if you copy the part of the code that defines tempfiles
to a do-file, run it, then try to reference the tempfiles, they will
be gone.  If you copy the code directly to the Command window, they
will still be there.  This is as expected if you understand the
behavior of locals.

Here is a simple example which requires you to save a section of code
to a do-file:

----------------do file
clear all
tempfile f
range id 0 1 2
save `f'
desc using `f'
do test
desc using `f'
di "$file"
desc using $file

On Jan 7, 2008 9:31 PM, David Kantor <[email protected]> wrote:
> Looking at example 1, it saves two files, but at the end, it just has
> what is present after creating the second dataset, d_student (and
> saving it, which is actually irrelevant); it makes no use of the
> first file after it is saved.
*   For searches and help try:

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