Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Two do-file log questions

    1) From within a do-file, is there some way to determine the filename of the do-file? I often want to have a do-file open a log file of the same name, without having to hardcode the name into the do-file, so that when I clone the do-file I don't have to remember to edit the logfile name.

    2) From within a do-file, is it possible to programmatically set the width of the results window, which determines the line length of a text log file, so that I can print the text log file without truncation caused by a results window wider than my printer line length?

    For (1), the altnernative for me is to write a general-purpose dofile (or for convenience an ado-file I think) that takes as its argument the do-file name, opens a log with that name, runs the do-file, and closes the log afterwards. If I did that, I guess I could have the general-purpose do-file capture noisily to run the called do-file, which would let the outermost do file close the log even if the innermost one failed. Maybe that's the way to go.

    For (2), I seem to have to fiddle with the window each time I run Stata [Stata/SE 13.1 for Mac (64-bit Intel) Revision 19 Dec 2014], perhaps because once Stata is launched, I immediately put it into the Mac full-screen mode. The description of set linesize found in help log is almost amusing in its documentation of its lack of general usefulness, perhaps to discourage former SAS users familiar with the linesize option in SAS. I am aware of creating SMCL logs and using translate, but I want text logs that I can read and print in a text editor outside of Stata. I don't place much value on the Stata formatting in SMCL. Perhaps I should?

    I'd appreciate hearing the voice of experience on this, over and above the answers to my specific questions. Am I trying too hard to match a non-Stata (i.e., SAS) work environment I have been productive in? Thanks in advance to anyone who can advise me on this.

  • #2
    1) Not possible. It's also something I want.
    2) There is the -set linesize- option (as you mentioned) but I remember it had some limitations.

    I agree about writing a program that -wraps- the do-files; it's something I tend to use but for other purposes (e.g. to send an email when a long do-file is done, or if there is an error).

    About the log file output, I think output format is probably one of the weakest points of Stata (e.g. when compared with R and other packages that even provide quite readable html output)

    Comment


    • #3
      SMCL is translatable into HTML. That makes it more valuable than you might think.

      Comment


      • #4
        Take a look at project (from SSC). project manages the execution of your do-files. It automatically logs do-files (each log file has the same name as the do-file with the appropriate log file extension). Within a do-file, you can use project, doinfo to get the name of the do-file, which you can then use to construct file names based on the name of the do-file. For example

        Code:
        project, doinfo
        local doname "`r(dofile)'"
        
        * do stuff
        
        save "`doname'.dta", replace

        Comment


        • #5
          Thanks to all for the advice. I ultimately decided to take the approach of having a program open a log, run the dofile, and close the log, also doing a few other things that I find useful. This is what I created.

          Code:
          program wjldo
          
          log using `1', text replace name(`1')
          set more off
          display " directory:  `c(pwd)'"
          
          capture noisily do `1'
          
          set more on
          log close _all
          
          end
          This is how it works, especially closing the log even if the dofile fails.

          Code:
          . wjldo test_wjldo
          ----------------------------------------------------------------------
                name:  test_wjldo
                 log:  /Users/lisowskiw/Research/Stata sandbox/test_wjldo.log
            log type:  text
           opened on:  16 Feb 2015, 17:13:16
           directory:  /Users/lisowskiw/Research/Stata sandbox
          
          . clear
          
          . gen x = 1
          
          . gem y = 2
          unrecognized command:  gem
          r(199);
          
          end of do-file
                name:  test_wjldo
                 log:  /Users/lisowskiw/Research/Stata sandbox/test_wjldo.log
            log type:  text
           closed on:  16 Feb 2015, 17:13:16
          ----------------------------------------------------------------------

          Comment

          Working...
          X