Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: to preserve locals while debugging


From   <Stefan.Gawrich@hlpug.hessen.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: to preserve locals while debugging
Date   Fri, 19 Mar 2010 12:18:09 +0100

Hi Statalisters,

I'm looking for a way to preserve locals while writing or debugging a
do-file . 

An example: 

I create a series of graphs in a loop. 
Graph parameters are provided by locals 
which are set inside the loop or somewhere else in the do-file.

Graph layout sometimes needs a lot of fine-tuning and visual checks.

Before running the graph again I have to redefine locals either 
by running the whole do-file or by temporarily defining all locals 
just above the graph command. Both alternatives are not very convenient.

I think of a command that stores all locals in a safe place 
(copy to global or something else) and breaks execution of the do file.

A complementary command restores the locals and makes them available for
the graph.

Anything already available or any ideas (beside "use globals")? ;-)

Stefan Gawrich



Simple code example 

sysuse auto, clear
local filename "auto.dta"
local foreign = 1
forval x = 1/5 {
lpres // preserves locals for the session and breaks at run 1 
...
}


To run while working on the graph:

lrest // restores locals
hist length if foreign == `foreign' & rep78 == `x', ///
title("`filename'")
}






*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index