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]

st: RE: log file lines numbers - can they be created/inserted


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: log file lines numbers - can they be created/inserted
Date   Thu, 18 Nov 2010 17:54:32 +0000

Interesting question. Absent any option for this in -log- that I can see, an evident alternative is to do it after the fact. 

In my own favourite text editor, there is an easy way to show line numbers, and probably a way to add line numbers, and what one smart text editor can do, another can. 

Alternatively, this quick and dirty utility passed precisely one test: 

*! 0.0.1 NJC 18 Nov 2010 
program lineno
	version 11.0
	syntax anything(name=file) , saving(str) [ replace ] 

	if "`replace'" == "" {
		confirm new file `"`saving'"' 
	}  

	tempname hi ho
	file open `hi' using `"`file'"', r
	file open `ho' using `"`saving'"', w `replace'
	file read `hi' line
	local i = 1 
	
	while r(eof) == 0 {
		file write `ho' "`i' " `"`macval(line)'"' _n
		file read `hi' line
		local ++i 
	}
	
	file close `ho'
end

Perhaps 11.0 can be decreased; meaning, I didn't test this in Stata 10 or lower. 

The code points up one tricky point: in just copying lines, you must be careful not to inhibit macro substitution. 

Nick 
[email protected] 

Ben Hoen

I often present output to the team of researchers working on the project I
have, and have found the log files to be the most useful to present results
in these preliminary stages (before any final output is needed to be
produced) Plots are exported via a separate bit of code.  

It would be extremely helpful to have line numbers display in a log file so
we all could quickly move to an output somewhere in a long file.  Is there a
way to do that?  Alternatively is there a way to have the output show the
line number of the .do file from which it is produced?

Any help would be greatly appreciated.  Thanks,


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