Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: to preserve locals while debugging


From   <[email protected]>
To   <[email protected]>
Subject   Re: st: to preserve locals while debugging
Date   Tue, 23 Mar 2010 09:29:21 +0100

Thanks Nick and Jeph for your replies

Nick Cox wrote:
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.


I agree but in my work I have to do a lot of "mass production" where 
the output is nearly the same for a lot of customers. So I often end up 
with huge do-files and loops. There might be other ways but despite the issue
discussed here I'm quite comfortable with that.


Jeph Herrin wrote a script to show that locals and contents of locals 
can  be parsed from -macro list-.

The idea works well but in this form only for simple locals.
I have some special cases so I altered it according to them:

There are issues with long locals going over several rows in -macro dir-.
I decided to take only the local names from -local dir- and take the 
content right out of the local. 

I often have several parts each containing several numbers or words 
in compound quotes in one local (e.g. different graph titles).
After a linebreak in -macro dir- it could happen that something like 
2007"' 
was the first word and caused errors in the -stringpos- function
even if compound quotes in -stringpos- were used. 
I eliminated all quotes from the first word of each line.

Here's the altered script:
It worked with all of my locals but I'm not sure if it can handle
each and every special case. 

**********

capture log close
log using mylocals2.txt, text replace
macro list
log close
file open logfile using mylocals2.txt, text read
file open mylocals using mylocals2.do, text replace write
file read logfile line
while r(eof)==0 {
	local lname : word 1 of `line'
		local lname : subinstr local lname `"""' ""
		local lname : subinstr local lname `"'"' ""
	if strpos("`lname'","_")==1  {
		local lval  : subinstr local line "`lname'" ""
		local lname : subinstr local lname "_" ""
		local lname : subinstr local lname ":" ""
		file write mylocals "local `lname' " _char(34) `"``lname''"' _char(34)  _n
	}
	
	file read logfile line
}
file close logfile
file close mylocals

**********

Thanks again

Stefan














*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index