Announcement

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

  • Putting regression results table into a pdf, using etable and putpdf

    I am trying to put some regression results into an etable and put that into a pdf.

    I can do it with a simple etable that has no options, however when I use options or if I want an etable that has results from multiple regressions, it seems putpdf won't accept it.

    This example does work (simple table):

    Code:
    sysuse auto, clear
    
    putpdf begin
    
        
        regress mpg weight
        
        putpdf table mytable = etable
    
    putpdf save results1.pdf, replace


    This example does not work:

    Code:
    sysuse auto, clear
    
    putpdf begin
    
        
        regress mpg weight
        
        putpdf table mytable = etable , cstat(_r_b) cstat(_r_se)     \\  option cstat(_r_b) cstat(_r_se) not allowed
    
    putpdf save results1.pdf, replace



    This example also doesn't work:

    Code:
        sysuse auto , clear
    
    
        
        reg mpg weight
    
        etable, cstat(_r_b) cstat(_r_se) cstat(_r_p) mstat(N) mstat(r2) showstars  showstarsnote
    
        
        
    * Add on more results to the etable
        
        qui reg mpg length
        
        etable, append
        
        qui reg mpg price
        
        etable, append
        
        
    putpdf begin
        
        putpdf table mytable = etable    // information for the estimation table not found;
                                                          //  putting the regressions after the "putpdf begin" also does not work
    
    putpdf save results2.pdf, replace
    Could someone share an example of putting an etable that uses options into a pdf? I am using Stata MP 17.0. Many thanks in advance!
    Last edited by James Barkin; 08 Apr 2024, 11:02.

  • #2
    This works:
    Code:
        sysuse auto , clear
    
    
        
        reg mpg weight
    
        etable, cstat(_r_b) cstat(_r_se) cstat(_r_p) mstat(N) mstat(r2) showstars  showstarsnote
    
        
        
    * Add on more results to the etable
        
        qui reg mpg length
        
        etable, append
        
        qui reg mpg price
        
        etable, append
        
        collect export results3.pdf, replace
    I should say, it works in version 18. I imagine it also works in version 17, but I can't be certain.


    Comment


    • #3
      putpdf table mytable = etable , cstat(_r_b) cstat(_r_se) \\ option cstat(_r_b) cstat(_r_se) not allowed
      There are two sets of options here: putpdf table's options and etable's options. For putpdf, only the following are allowed:

      tablename specifies the name of a new table. The name must be a valid name according to Stata's naming conventions; see [U] 11.3 Naming conventions.

      table_options Description
      --------------------------------------------------------------------------------------------------------------------------------------------------------------------
      memtable keep table in memory rather than add it to document
      width(#[unit|%] | matname) set table width
      halign(hvalue) set table horizontal alignment
      indent(#[unit]) set table indentation

      spacing(position, #[unit]) set spacing before or after table
      border(bspec) set pattern and color for border
      title(string[, cell_fmt_options]) add a title to the table
      note(string[, cell_fmt_options]) add a note to the table
      --------------------------------------------------------------

      Could someone share an example of putting an etable that uses options into a pdf?
      etable's output can be directly exported as PDF in Stata 18. I am not sure about Stata 17.

      Code:
      sysuse auto , clear
      reg mpg weight
      etable, cstat(_r_b) cstat(_r_se) cstat(_r_p) ///
      mstat(N) mstat(r2) showstars showstarsnote ///
      export(results1, as(pdf) replace)
      You could also do all this with collect in version 17.

      Code:
      help collect

      Comment


      • #4
        Thank you Clyde and Andrew, both of those examples work great for Stata 17.

        One follow up question, is it possible to put graphs into the same pdf, along with the tables?

        I tried reading the doc for collect and it seems not intended for graphs, only tables. I know putpdf can accept graphs, but it seems I need to avoid putpdf in these examples to write tables.


        I tried the following:

        Code:
            sysuse auto, clear
            reg mpg weight
            etable, cstat(_r_b) cstat(_r_se) cstat(_r_p) mstat(N) mstat(r2) showstars  showstarsnote
                
        
        * Make a graph
        
            collect: scatter mpg weight
            
            
        * Write to pdf
        
            collect export results3.pdf, replace    // only has the table

        Comment


        • #5
          collect is for tables, you cannot collect an image. You were on the right track in #1 with putpdf.

          Code:
          sysuse auto, clear
          putpdf begin
          reg mpg weight
          etable, cstat(_r_b) cstat(_r_se) cstat(_r_p) mstat(N) mstat(r2) showstars  showstarsnote
          putpdf collect
          scatter mpg weight, saving(gr1, replace)
          gr export gr1.png, as(png) replace
          putpdf paragraph
          putpdf image gr1.png
          putpdf save results1.pdf, replace
          Res.:
          Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	27.3 KB
ID:	1749454


          Last edited by Andrew Musau; 09 Apr 2024, 14:27.

          Comment

          Working...
          X