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: RE: log file lines numbers - can they be created/inserted


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

Nefarious negative needs negation: You must be careful to inhibit macro substitution. 

Nick 
[email protected] 

Nick Cox

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] 


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