This is a solution I have used to do what Raoul is describing.
He will have to adapt this depending on whether he is asking the do-
files to run from a loop or each one has its own -do- command.
This will create an error log TXT file which contains the file path/
name of the do-file that gave an error & a timestamp to help keep it
all straight. In order for this to run, I always put "exit=0" at the
end of all of the non-master do-files & turn -rmsg off- so that, if it
runs without issues, the error code will be zero. (I'm not sure if
it's absolutely necessary to do this, but I do it just to avoid
problems I had with getting this to run).
**********
clear
cap set rmsg off
tempname errorlog
cap file close errorlog
file open errorlog using "/user/errorlog.txt", write text replace
**DO-FILE ONE
capture noi {
local file1 "/user/surveyb.do"
do `file1'
}
if _rc != 0 {
di "Error Occured in `file1' ; Timestamp: `c(current_date)' : `c
(current_time)'"
cap file close errorlog
file open errorlog using "/user/errorlog.txt", write text append
file write errorlog "`file1' ; Timestamp: `c(current_date)' : `c
(current_time)'" _n
}
**DO FILE TWO
capture noi {
local file2 "/user/surveya.do"
do `file2'
}
if _rc != 0 {
di "Error Occured in `file2' ; Timestamp: `c(current_date)' : `c
(current_time)'"
cap file close errorlog
file open errorlog using "/user/errorlog.txt", write text append
file write errorlog "`file2' ; Timestamp: `c(current_date)' : `c
(current_time)' " _n
}
//and keep going for all your do files, or set them up in a loop......
**
cap file close errorlog
**********
Best,
Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Sep 30, 2009, at 1:34 PM, Sergiy Radyakin wrote:
No, Stata does not report the file and line number where the error
has occured.
There are different ways to get around this by injecting
comments/display statements throughout the code. None satisfies me so
far.
Also, consider changing your project. Stata is not very capable of
managing a project of 100 files (in the Microsoft Visual Studio
sense).
Perhaps this could be reduced to 2 files, where one master file calls
a another file with some parameters?
Best regards, Sergiy Radyakin
On Wed, Sep 30, 2009 at 2:13 PM, Michael I. Lichter
<[email protected]> wrote:
If you're on Unix/Linux or use Cygwin or the equivalent you can
include a
distinctive header in each file that includes the name of the file
and use
-egrep- and -tail- to locate the name of the last do file that began
executing. So, your header might be
// program: fritz.do -- compute the fritz statistic
and you would run
!egrep '// program: ' master.log | tail -1
which would identify the failed file. It wouldn't be too difficult
to write
a Stata program to do the same thing using -file read-.
Michael
raoul reulen wrote:
I run one master do file that runs ~100 other do-files. When I get
an
error message I need to know in what do-file the error occured. Is
there an easy way in Stata to find out what the last do-file was
without having to scroll through the output?
Thanks
Raoul
*
* 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/
--
Michael I. Lichter, Ph.D. <[email protected]>
Research Assistant Professor & NRSA Fellow
UB Department of Family Medicine / Primary Care Research Institute
UB Clinical Center, 462 Grider Street, Buffalo, NY 14215
Office: CC 126 / Phone: 716-898-4751 / FAX: 716-898-3536
*
* 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/
*
* 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/
*
* 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/