Ashim Kapoor --
You can add all the requisite strings to the data by adding
characteristics to the data (-help char-), or -notes-, or new
variables, or use a variety of other tricks, but in order to have
those objects returned to the local and global macros you want in a
new Stata session, you would have to write a do file that does
that--it's much more straightforward just to write a do file defining
the locals and globals directly. Let's assume for the purposes of
argument you can't do that because you don't know what the locals and
globals are--then you can write a program to write the do file for
you, but it can only save the globals, because any locals will be
invisible to a program you run. So you would need to switch from
locals to globals for all your code leading up to the saving
procedure. Here's a program that saves all extant globals to a
do-file that recreates them in a new Stata session, assuming they are
fairly short strings (less than 240 characters or so):
prog logmac
syntax using [, replace]
cap log close
tempfile t
cap log using `"`t'"', text
ma li
cap log close
tempname f fh
file open `f' `using', write `replace'
file open `fh' using `"`t'"', read
file read `fh' line
while r(eof)==0 {
gettoken n line: line
if !inlist(substr("`n'",1,1),"_","-") {
loc n=substr("`n'",1,length("`n'")-1)
file write `f' `"glo `n' `"`=trim(`"`line'"')'"'"' _n
}
file read `fh' line
}
file close `fh'
end
I can't see that it is of much use, though...
*
* 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/