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
Maarten buis <[email protected]>
To
[email protected]
Subject
Re: st: log file lines numbers - can they be created/inserted
Date
Thu, 18 Nov 2010 17:47:01 +0000 (GMT)
--- On Thu, 18/11/10, Ben Hoen wrote:
> 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?
Below is a rough first version of a command -log_ln- that
add line numbers to a log file.
*-------------------- begin example ----------------------
program drop _all
// program begins
*! version 1.0.0 MLB 18Nov2010
program log_ln
version 11.1
syntax using/, save(string) [replace append]
confirm file `"`using'"'
if "`replace'`append'" == "" {
confirm new file `"`save'"'
}
tempname fh_r fh_w
local linenum = 0
file open `fh_r' using `"`using'"', read
file open `fh_w' using `"`save'"', write `replace' `append'
file read `fh_r' line
while r(eof)==0 {
local linenum = `linenum' + 1
file write `fh_w' %4.0f (`linenum') `" `macval(line)'"' _n
file read `fh_r' line
}
file close `fh_r'
file close `fh_w'
end
// program ends
// example begins
cd c:\temp
log using foo, replace
sysuse auto, clear
reg price mpg
log close
log_ln using "c:\temp\foo.smcl", save("c:\temp\foo2.smcl") replace
// example ends
// view results from example
view "c:\temp\foo2.smcl"
type "c:\temp\foo2.smcl"
*----------------------------- end example ----------------------------
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/