Announcement

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

  • Using log to only safe certain parts of the output

    Dear All,
    I am trying to use log to create an output PDF containing only some selected parts of my output. Consider the following minimal example:

    Code:
    clear
    set obs 100
    cd "C:\Users\jannic\Dropbox\Pelizzon\QE - Insurances - Copy Jannic\sandbox"
    log using testlogfile.smcl, replace
    
    
    gen x = rnormal()
    tab x
    log on
    di "test text: " `r(N)'
    log off
    log close
    
    translate testlogfile.smcl testlogfile.pdf, replace
    I want the PDF to read: "test text: 100". is there a way to surpress everything else? I understand that the entire log file is helpful as well, but I would like this as a summary log file for the non technical people on the team. however I don't want to write it manually, everytime I change some procedures. Can anyone help me out?

    Best,
    Jannic


  • #2
    There are a couple of issues here. I haven't found a way to get exactly what you want, but I can come close.

    Issue 1. Stata writes some "metadata" when you open or close a log file. You can prevent most of that by doing it -quietly-, but the -quietly log close- command is itself echoed to the log file.

    Issue 2. opening a log file results in information about the file being returned in r(), so the previous contents of r(N) are lost. So those have to be saved before you open the log file.

    The following is as close as I could come:
    Code:
    clear
    set obs 100
    
    gen x = rnormal()
    tab x
    local N `r(N)'
    quietly log using testlogfile.smcl, replace
    di "test text: " `N' "
    quietly log close
    
    translate testlogfile.smcl testlogfile.pdf, replace
    That said, a problem with this is that you will have no real record of the process for yourself. You will have produced a stripped down "answers only" file for those who want to see just that. But if challenged later about how you got those results, there will be no documentation. So, if I were you, I would take advantage of Stata's ability to use multiple logs with different handles. (The documentation calls them names, but these names are not the actual filenames, so they are really handles.). I would log the entire session in one of those logs, and use the other log for the "answers only" part. If you are not familiar with multiple logs and handles ("names") read -help log- and the accompanying material in the user's manual.

    Comment


    • #3
      Dear Clyde Schechter, thanks! Yes I will probably look into the multiple logs thing. Sounds like a nice feature!

      Comment

      Working...
      X