There is some confusion here between _where_ and _when_.
A local macro (don't attach the word "variable" here,
as it doesn't apply) can last a whole session so
long as it is defined interactively and you
don't overwrite or delete it. Thus if you were
to define your -local base ...- in the Command
window this would stick around, so long as you
yourself don't zap it, to the end of the session.
By defining a -local- within a .do file you
are saying to Stata that the macro should persist
only to the end of the file (which here by
courtesy is considered a kind of program).
That's what "local" means, precisely: _local_ to the
program in which it is defined, where "program"
is in a wide sense one of
a sequence of commands typed interactively
a -program- explicitly defined (e.g. within
an .ado file)
a .do file
the contents of the do-file editor executed.
There is a way of defining locals that will persist
from within .do files. It is called -c_local- and
it is not documented (it is not even under -undocumented-).
The usual coy advice is that you shouldn't use it until
you have worked out for yourself from examples how it
works and why it can be dangerous.
All that said, the advice of Philipp Rehm to use -global-s
instead is good. But globals also will only last an
entire session if they are not zapped.
Nick
[email protected]
[email protected]
> I was wondering if anyone knows how to define or save macro
> variables so they last for an entire stata session and not
> just while the do-file is running. I've been defining macro
> variables as is below with the local command where the
> command `base' substitutes for all the variables in quotes
> below for example. But if I run the local command, and then
> later highlight some line of code with `base' and "do" it,
> then Stata no longer associates `base' with the set of
> variables. Anyone know any ways around this problem? I've
> tried saving using global macros and that doesn't seem to help.
>
> local base "lncgdp s n popuned popprimed popseced pophighed openc"
>
> regress `base'
*
* 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/