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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: RE: to preserve locals while debugging


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: to preserve locals while debugging
Date   Fri, 19 Mar 2010 11:53:16 -0000

I understand the question but I don't have a good sense of why you
dislike the solutions, which in essence you already know. 

I think the main trick is to keep all the locals you need together with
the graph commands in a _small_ .do file. That is, as a .do file can
call other .do files, storing definitions together with commands is the
most obvious way to go. 

Also, you can pass arguments to do-files and them map to locals using
-args-. 

do mydo foo bar frog toad 

* mydo.do 
args filename gtype yvar xvar 

Alternatively, you may be seeking -c_local-. The usual comment about
-c_local- is that you are ready to use it when you have come across it,
have worked out how to use it, and know how dangerous it can be. Less
gnomically, a search of the Statalist archives will yield some examples.


I don't think using -c_local- is nearly as good a solution as exploiting
the full flexibility of .do files. 

Nick 
n.j.cox@durham.ac.uk 

Stefan.Gawrich@hlpug.hessen.de

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