Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: DO file name macro


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: DO file name macro
Date   Thu, 22 Jul 2004 15:26:14 +0100

Adding important bells and whistles like 
this is a good way to go. Note incidentally 
that my code requires a "do" to work: 

do mydo mylog.txt example.do 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of David Kantor
> Sent: 22 July 2004 15:22
> To: [email protected]
> Subject: RE: st: RE: DO file name macro
> 
> 
> Nick gave a nice trick in response to Eddy's question about 
> displaying the 
> do-file name.
> 
> At 12:45 PM 7/22/2004 +0100, you wrote:
> >Perhaps you can this by indirection:
> >
> >--------------------- mydo.do
> >log using `1'
> >di "`2'"
> >do `2'
> >---------------------
> >
> >Thus
> >
> >mydo mylog.txt example.do
> >
> >is interpreted as
> >
> >log using mylog.txt
> >di "example.do"
> >do example.do
> >
> >Use " " to bind filenames with spaces.
> >[...]
> 
> This is similar in spirit to a little program I wrote 
> recently.  Mine opens 
> a log and invokes a do-file, both with the same base name (as 
> is typical in 
> the way I work); it then closes the log, unless you use the -noclose- 
> option.  It uses -syntax- and has some code to check for various 
> conditions.  Here is is, in case anyone wants it.  This is a 
> bit different 
> from what Eddy asked for in that it assumes that the log and 
> do-file will 
> have the same base name. But it could be altered to use 
> possibly distinct 
> names.  Also, it has -text- as the hard-coded log type; that 
> could be made 
> into an option as well.
> 
> You invoke this as...
>   dolog using filename
> or
>   dolog using filename, noclose
> in case you want the log to remain open.
> 
> 
> -- David
> /*
> dolog.ado
> David Kantor, 7-1-2004
> 
> This makes it easier to log a run -- with the basename of the 
> log the same as
> the run.
> 
> Do a text log.  On might possibly make this flexible in 
> allowing the choice
> of smcl vs text (or the default).
> 
> */
> 
> *! version 1.0.0 7-1-2004
> 
> prog def dolog
> version 8
> 
> quietly log
> if "`r(filename)'" ~= "" {
>   disp as err "log already open"
>   exit 604
> }
> 
> syntax using/ , [noclose]
> 
> disp "log using `using', t"
> capture noisily log using `using', t
> 
> if _rc {
>   disp as err "problem in log command; try again with 
> -replace- (y/n)?" 
> _req(ans)
>   if upper("$ans") == "Y" {
>     disp "log using `using', t replace"
>     capture noisily log using `using', t replace
>   }
> }
> 
> if ~_rc {
>   disp "do `using'"
>   do `using'
>   if "`close'" == "" {
>    log close
>   }
> }
> 
> end
> ----
> 
> David Kantor
> Institute for Policy Studies
> Johns Hopkins University
> [email protected]
> 410-516-5404
> 
> *
> *   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/
> 

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