Bob
I can't see any reason why Scott's code wouldn't have removed these...
Was your clean_log1.log file created as text or smcl? Scott's code
relies on it being a text log, as it looks for "r(" at the start of a
line, whereas a smcl log would say something like "{txt}{search
r(111):r(111);}"
I have had a quick go at coding a command -rmlogerr-, below. Syntax is
just the two file names, with a replace option to allow the new file to
overwrite an existing file, e.g. -rmlogerr "my old log.log" "my clean
log.log", replace-. This should do what you want and work for both text
and smcl logs. It does assume that all commands are being logged as well
as their output (i.e. the log was produced interactively or by -do-ing a
.do file not -run-ning it). Everything from an error return code "r(*)"
back to the previous command (indicated by the Stata prompt "."), plus
one blank line after the error, is stripped out.
Give it a go and see what you think. I haven't tested it extensively.
David
prog rmlogerr
version 9
syntax anything(id="file names") [, replace]
tokenize `"`anything'"'
tempname old new
file open `old' using `"`1'"', read
file open `new' using `"`2'"', write `replace'
file read `old' newline
local eof = r(eof)
if `"`newline'"'=="{smcl}" {
local com 0
while !`com' & !`eof' {
file write `new' `"`newline'"' _n
file read `old' newline
local eof = r(eof)
local com = substr(`"`newline'"',1,7)=="{com}. "
}
while !`eof' {
local i 1
local line`i' `"`newline'"'
file read `old' newline
local eof = r(eof)
local com = substr(`"`newline'"',1,7)=="{com}. "
local err = strmatch(`"`newline'"',"{txt}{search
r(*):r(*);}")
while !`com' & !`err' & !`eof' {
local line`++i' `"`newline'"'
file read `old' newline
local eof = r(eof)
local com = substr(`"`newline'"',1,7)=="{com}. "
local err = strmatch(`"`newline'"',"{txt}{search
r(*):r(*);}")
}
if !`err' {
forvalues j=1/`i' {
file write `new' `"`line`j''"' _n
}
}
else {
file read `old' newline
if `"`newline'"'=="" {
file read `old' newline
}
local eof = r(eof)
local com = substr(`"`newline'"',1,7)=="{com}. "
local err = strmatch(`"`newline'"',"{txt}{search
r(*):r(*);}")
}
}
}
else {
local fc = substr(`"`newline'"',1,2)
while "`fc'"!=". " & !`eof' {
file write `new' `"`newline'"' _n
file read `old' newline
local eof = r(eof)
local fc = substr(`"`newline'"',1,2)
}
while !`eof' {
local i 1
local line`i' `"`newline'"'
file read `old' newline
local eof = r(eof)
local fc = substr(`"`newline'"',1,2)
while "`fc'"!=". " & "`fc'"!="r(" & !`eof' {
local line`++i' `"`newline'"'
file read `old' newline
local eof = r(eof)
local fc = substr(`"`newline'"',1,2)
}
if "`fc'"!="r(" {
forvalues j=1/`i' {
file write `new' `"`line`j''"' _n
}
}
else {
file read `old' newline
if `"`newline'"'=="" {
file read `old' newline
}
local eof = r(eof)
local fc = substr(`"`newline'"',1,2)
}
}
}
file close `old'
file close `new'
end
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Robert A
Yaffee
Sent: 11 May 2006 13:30
To: [email protected]
Subject: Re: st: RE: Pgm 2 remove grammatical errors in log
Scott,
I ran three regressions on auto.dta. Two were incorrect. When I ran
your program on it, the program seems to have left the error indicators
in the clean_log1.log file.
- Bob
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/