Announcement

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

  • Esttab to latex: make notes table-width

    Hi Statalisters,

    I'm running several regressions and creating multiple tables (each containing multiple regressions) using esttab, such as the example below.

    Code:
     
      sysuse auto.dta, clear
      generate wtsq = weight^2
    
      
    * create table 1
      eststo clear
    
      regress mpg weight
      eststo a
    
      regress mpg weight wtsq
      eststo b
    
      regress mpg weight wtsq foreign
      eststo c
      
      esttab a b c using "table1.tex", replace addnotes("A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width.")
      
    * create table 2
      eststo clear
      
      regress price headroom
      eststo a
      
      regress price headroom trunk
      eststo b
      
      regress price headroom trunk length
      eststo c
      
      esttab a b c using "table2.tex", replace addnotes("A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width.")
    I then wrote a LaTex file that reads:
    Code:
    \documentclass[a4paper, hidelinks]{article}
    \usepackage{amsmath,
               amssymb,
               amsthm,
               appendix,
               bbm,
               booktabs,
               caption,
               color,
               enumitem,
               etoolbox,
               fancyhdr,
               float,
               graphicx,
               hyperref,
               inputenc,
               latexsym,
               mathtools,
               multicol,
               natbib,
               parskip,
               pdflscape,
               pgfplots,
               setspace,
               soul,
               tikz,
               titlesec,
               titling}
    \usepackage[margin=.2in]{geometry}
    \usepackage{grffile}
    
    % wrap addnotes text
    % \newcommand{{l}{\footnotesize Notes:}}{{@{}p{.9\linewidth}@{}}{\footnotesize Notes:}} NOT WORKING
    
    \begin{document}
    
    \input{"table1.tex"} %stata's latex output
    \input{"table2.tex"} %stata's latex output
    
    \end{document}
    This creates a runaway note at the bottom of each table. I'd like to make each note table-width. The outputted latex code from stata reads:
    Code:
    \multicolumn{4}{l}{\footnotesize A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width.}
    According to this link, I could replace the outputted stata code with
    Code:
    \multicolumn{4}{@{}p{\linewidth}@{}}{\footnotesize{\footnotesize A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width. A very long note that I would like to wrap at table width.}
    which works. However given that I'm doing this for dozens of tables, I'd like to know how to do this globally in my latex preamble.

    TIA!

  • #2
    After much searching, found an (albeit, less than elegant) solution. https://www.statalist.org/forums/for...multiple-lines Hallelujah! Still, open to something more straightforward if anyone knows!

    Comment

    Working...
    X