Announcement

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

  • Stata14 export results to PDF

    Dear community,

    I am new to STATA and to this forum as well. I am in the process of familiarising myself with STATA (14) but now face a problem that seems very trivial but I cannot find the solution for the life of me. I simply would like to export all the output that appears in my results window as a PDF document. There seems to be no button to click on in order to do this. The translate command does not help me. I read the help translate file but cant find out what I am doing wrong or what I should type as command.

    Can please somebody advise? It seems like something that should not be that hard to do.

    Any help would be really appreciated!

  • #2
    Timbo:
    welcome to the Stata (not STATA please, as per FAQ) forum.
    You can simply copy and paste your Stata session on a Do-file and then print all the stuff via the Print command available scrolling down the File menu in the Do-file editor.
    If you have a .pdf Printing option installed on your desk/laptop the job is done.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      As does Carlo, I typically created PDFs using the macOS Print dialog box to save the "prinout" as a PDF rather than send it to the printer. I cannot speak for Windows or Linux.

      But since today seems to be my day for answering questions about the translate command, here is an example. The tools you need are described in
      Code:
      help log
      help translate
      I run this code from the Do-file editor windows.
      Code:
      log using "~/Downloads/pretend.smcl", replace
      sysuse auto, clear
      summarize weight length
      log close
      translate "~/Downloads/pretend.smcl" "~/Downloads/pretend.pdf", replace
      This is what I see in the Results window.
      Code:
      . log using "~/Downloads/pretend.smcl", replace
      ------------------------------------------------------------------------------------------------
            name:  <unnamed>
             log:  /Users/lisowskiw/Downloads/pretend.smcl
        log type:  smcl
       opened on:   3 Jun 2020, 12:18:41
      
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . summarize weight length
      
          Variable |        Obs        Mean    Std. Dev.       Min        Max
      -------------+---------------------------------------------------------
            weight |         74    3019.459    777.1936       1760       4840
            length |         74    187.9324    22.26634        142        233
      
      . log close
            name:  <unnamed>
             log:  /Users/lisowskiw/Downloads/pretend.smcl
        log type:  smcl
       closed on:   3 Jun 2020, 12:18:41
      ------------------------------------------------------------------------------------------------
      
      . translate "~/Downloads/pretend.smcl" "~/Downloads/pretend.pdf", replace
      
      .
      end of do-file
      
      .
      This is a screenshot of the top of the PDF (screenshot so you don't have to open a link to see it).
      Click image for larger version

Name:	pretend.png
Views:	1
Size:	189.7 KB
ID:	1556722

      Comment


      • #4
        Thank you guys!

        Comment


        • #5
          @William Lisowski Is there some way to update your code above so that the pdf only includes the results and no code?

          Comment


          • #6
            Originally posted by Andrew Caporaso View Post
            @William Lisowski Is there some way to update your code above so that the pdf only includes the results and no code?
            This doesn't seem well-suited to logs, which are intended to record the process including the commands.

            Seems more like a job for one of the reproducible research tools -- dyndoc, putdocx or putpdf built into Stata, or one of the user-written alternatives (markstat, markdoc, webdoc are the ones I'm aware of, there may be others).

            Comment


            • #7
              One approach (hack?) here is to use -log- to create a .smcl file, per #3 above. This is just a plain text file with lots of markup. You can then bring it into a text editor in which you will see that every command line begins with "{com}," as in a few examples I have excerpted from the .smcl at #3:

              Code:
              {com}. sysuse auto, clear
              ...
              {com}. summarize weight length
              ...
              You can then use a text editor with reasonable search/replace sophistication to find and delete "all lines that begin with "{com}" in that smcl file, which can be saved as a text file with the smcl extension, after which Stata's -translate- can create a pdf, as suggested at #3.

              In fact, you can use Stata itself to do this. Here's a mildly clumsy but functional illustration of what the pure Stata solution might look like:
              Code:
              // Create some results for illustration
              log using "MyFile.smcl", replace
              sysuse auto, clear
              summarize weight length
              log close
              //
              clear
              // Bring in the smcl file to clean out the commands.
              //
              // Set up a convenient nonprinting character to serve as a "fake" delimiter,
              // since we don't want or have such a delimiter.
              local c1 = char(1)
              import delimited "MyFile.smcl", ///
                 delimiter("`c1'", asstring) varnames(nonames) stringcols(_all) clear 
              drop if substr(v1, 1,5) == "{com}"
              // Save the "clean" smcl (text) file and have Stata translate it to pdf.
              export delimited using "MyFile2.smcl", delimiter("`c1'") novarnames replace
              translate "MyFile2.smcl" "MyFile2.pdf", replace

              Comment


              • #8
                Using webdoc stlog with the cmdstrip option should give you what you want.

                Jann, Ben (2017). Creating HTML or Markdown documents from within Stata using webdoc. The Stata Journal 17(1): 3-38.

                https://repec.sowi.unibe.ch/stata/webdoc/index.html

                Comment

                Working...
                X