Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: save "`table1'"

From   "Sarah Edgington" <>
To   <>
Subject   RE: st: save "`table1'"
Date   Fri, 27 Dec 2013 11:58:25 -0800

The problem is that you're running line-by-line.
Stata does not retain local macros (including tempfiles) across sessions.  You'll notice that when you select text in a do file and hit do that Stata issues a -do- command that references a .tmp file. From Stata's perspective each time you hit do on a selected block of code you're running a new file.  Stata will not retain the local macros from the last do file it ran.  So if the local is not defined within the block of code that you're running, the local will be undefined.  If you run all the parts of the dofile that reference `table1' at once you shouldn't have a problem.  Alternatively you can type (or copy) lines into the command line.  As long as you don't close Stata or -do- or -run- a new dofile you'll retain your local macros.

In short, locals are only available in the following contexts:
1. within a single interactive sessions
2. within a single do file.  Remember that even if it's saved in a single file, if you aren't running the whole thing at once Stata will treat each separate block of commands that you run as a new do file.
3. within a single program.  (If you're not using the -program- command don't worry about this).

The documentation for the macro commands is geared toward programming in the sense of using the -program- command.  Nonetheless, if you're using either local or global macros in your do files you should read the section of the manual Phil pointed out to get a better understanding of how they work.


-----Original Message-----
From: [] On Behalf Of Rongrong Zhang
Sent: Friday, December 27, 2013 11:13 AM
Subject: Re: st: save "`table1'"

Thank you Phil!

Yes , before save "`table1'", there was
tempfile table1

save "`table1'"

but I ran line by line, why did I get

. tempfile table1

end of do-file

. do "C:\Users\rzhang\AppData\Local\Temp\STD00000000.tmp"

. save "`table1'"
invalid file specification

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index