Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: saving contents of macros

From   <[email protected]>
To   <[email protected]>
Subject   st: RE: saving contents of macros
Date   Mon, 31 Jan 2005 13:05:46 +0100

that's not easy to do. To my knowledge no command exists to list the
globals and locals 
ready for processing; -macro list- does not leave anything in r().
However, you could try a work-around with tempvars:

forvalues i = 1(1)20 {
	tempvar m`i'
	// Assign your values
This may work only in a limited number of cases.
One may conceive of other work-arounds. The least convenient one may be
to -macro list-
the macros, copy the output from the results window, paste it into
some text file and then read in this text file, separating macro names
from their values.

Storing itself is easy:
You write the macros to a text file, which you later may read in.

To write, something like this should work (excerpted from the code of my
where I have to store some values between Stata sessions):

	tempname rfllog
	file open `rfllog' using `"`:sysdir PERSONAL'rfl.log"', write
text replace
	file write `rfllog' "`strucversion'" _n
	file write `rfllog' "`hidemenu'" _n
	file close `rfllog'

To read, try something along these lines:

	tempname rfllog
	file open `rfllog' using `"`:sysdir PERSONAL'rfl.log"', read
	file read `rfllog' line
	local strucversion `line'
	file read `rfllog' line
	local hidemenu `line'
	file close `rfllog'

Instead of known macro names, take `m`i'' and put them in a forvalues
loop, or
do further processing with the lines to separate names from values.
The tempvar solution implies that you know what m`i' denotes after
you've read in the file...
Don't know whether this really suits your problem, but I hope it helps.
Dankwart Plattner

Michael Ganz wrote:

I've looked high and low but I can't find anything on this:
Is there a way to save the contents of all of the global and local
currently in memory to a file so that they can be restored later after 
restarting Stata?

Die in dieser E-Mail und den dazugehoerigen Anhaengen (zusammen die "Nachricht") enthaltenen 
Informationen sind nur fuer den Adressaten bestimmt und koennen vertrauliche und/oder rechtlich 
geschuetzte Informationen enthalten. Sollten Sie die Nachricht irrtuemlich erhalten haben, loeschen 
Sie die Nachricht bitte und benachrichtigen Sie den Absender, ohne die Nachricht zu kopieren oder 
zu verteilen oder ihren Inhalt an andere Personen weiterzugeben.

Ausser bei Vorsatz oder grober Fahrlaessigkeit schliessen wir jegliche Haftung fuer Verluste oder 
Schaeden aus, die durch virenbefallene Software oder E-Mails verursacht werden.
The information contained in this e-mail and any attachments (together the "message") is intended 
for the addressee only and may contain confidential and/or privileged information. If you have 
received the message by mistake please delete it and notify the sender and do not copy or 
distribute it or disclose its contents to anyone.

Except in case of gross negligence or wilful misconduct we accept no liability for any loss or 
damage caused by software or e-mail viruses.

*   For searches and help try:

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