Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Does a do file know its own name?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Does a do file know its own name?
Date   Thu, 16 Aug 2007 17:07:48 +0100

I think the answer to your subject question is No, 
in several senses. 

More seriously, what I think you want to do is 
achievable in this way: 

-------------------------------- mydo.do 
log using `2' 
di "dofile `1'" 
do `1' 
log close 
--------------------------------

Then you would type something like this 

do mydo foobar.do foobar.log 

and -mydo.do- would first open a log, here 
foobar.log, then echo the name of the 
do-file, here foobar.do, then run said do
file. 

There are endless possible small variations 
on this. Filenames with embedded spaces 
must be delimited by " " as usual. 

However, this seems more indirect than 
opening a log before issuing -do- or 
-run-. That way, the name of the do 
file is included in the log in any case. 


Nick 
[email protected] 

Skinner Jane Dr (MED)
 
> Is there any way of obtaining the string "MyDoFile" programmatically
> from within MyDoFile.do?  I would like to write to a log file with
> the same name (different extension, obviously) in a way that is
> robust to renaming or copying the do file, amongst other things.

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index