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: log file lines numbers - can they be created/inserted
From 
 
"Ben Hoen" <[email protected]> 
To 
 
<[email protected]> 
Subject 
 
RE: st: log file lines numbers - can they be created/inserted 
Date 
 
Thu, 18 Nov 2010 13:34:45 -0500 
Thanks Guys!
Nick, what, pray-tell, is the "smart" text editor you use?  (Mine - Notepad
- is evidently as dumb as a doornail.)
Ben
=============
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]
Ben Hoen
LBNL
Office: 845-758-1896
Cell: 718-812-7589
[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/