Announcement

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

  • Adding row of text to LaTeX table produced with esttab?

    I'm creating a table of the mean from summary statistics. I'm trying to add a row under my column titles/ before other table data that lists string "Sample Date" for each of my column. I've tried using refcat(), scalar(), and other hacks I found on google that have been unsuccessful. The code below came closest to what I wanted, but the sample dates were listed where "obs" would normally go at the bottom of the table below an hline. Any help would be greatly appreciated!

    Code:
    label var qty1 "Number of Books" 
    label var qty2 "Number of Pages" 
    label var avg1 "Average no. pages per shelf" 
    label var avg2 "Average no. books per shelf" 
    label var avg3 "Average no. pages per book"
    
    estpost su qty1 qty2 avg1 avg2 avg3 if library == 1
    est store A
    estadd local sampdate "June 2000", replace
    
    estpost su qty1 qty2 avg1 avg2 avg3 if library == 0
    est store B
    estadd local sampdate "December 2003", replace
    
    esttab A B using "test2.tex", replace ///
        label mtitle("\textbf{Library 1}" "\textbf{Library 2}") ///
        cells(mean(fmt(%9.0fc))) width(.9\hsize) collabels(none) nonum gaps noobs wide ///
        scalar("sampdate Sample Dates")

  • #2
    esttab/ estout is from SSC/Stata Journal. You can add the -plain- option of estout to remove the default horizontal lines and then add your own as specified in the following link.

    https://www.statalist.org/forums/for...e-using-estout

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      esttab/ estout is from SSC/Stata Journal. You can add the -plain- option of estout to remove the default horizontal lines and then add your own as specified in the following link.

      https://www.statalist.org/forums/for...e-using-estout
      Thank you! This is very helpful for the line options. Given I want my first row to be my "Sample Date" row, which will be populated with strings, do you have any suggestions for how to move that row from the bottom, to the first row? I've read through the esttab/ estout documentation, but have not found anything for what I'm trying to accomplish.

      Comment


      • #4
        Does it work if you put them just below the model title?

        Code:
        mtitle("\shortstack{\textbf{Library 1}\\June 2000}" "\shortstack{\textbf{Library 2}\\December 2000}")
        You could also add a space in between

        Code:
        mtitle("\shortstack{\textbf{Library 1}\\ \\June 2000}" "\shortstack{\textbf{Library 2}\\ \\December 2000}")

        Because you introduce the text as a scalar in #1, you cannot move it up as scalars come below the results.

        Comment


        • #5
          Andrew Musau It does work, but I'm not able to assign the "Sample Date" variable name in the left hand column. I'm currently also trying to just make the Sample Dates row as a scalar in one table, then append that table with the rest of my rows, but there are many alignment issues that the alignment() command is not fixing. Thank you for all of your help!

          Comment


          • #6
            but I'm not able to assign the "Sample Date" variable name in the left hand column.
            Switch to estout's -mlabel()- option in place of esttab's -mtitle()- and specify the sub-option -lhs()- to include text in the first column.

            Code:
            mlabel("\shortstack{\textbf{Library 1}\\ \\June 2000}" "\shortstack{\textbf{Library 2}\\ \\December 2000}", lhs(\\ \\Sample Dates))
            I'm currently also trying to just make the Sample Dates row as a scalar in one table, then append that table with the rest of my rows
            I think the default alignment is to center the text but if you want to align right or left, one way in LaTeX is to add a tilde ("~") for each letter at the beginning or end of the word to match the longest word. So mountain is 8 letters and lake is 4, to right-align, I would write lake as "~~~~lake" and to left-align, "lake~~~~".
            Last edited by Andrew Musau; 22 Nov 2019, 15:22.

            Comment

            Working...
            X