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

  • Add horizontal line to table in latex using esttab


    This involves the use of the SSC available command esttab (available via SSC install estout).

    I have added some scalars to a table of regression coefficients, and then the observations after that (via the obslast option). I would like to add a horizontal line after the scalars (before the observations) in my latex table.

    I can figure out how to add the line before or after a variable name via varlabels(, blist(var1 "\hline"))

    The example here: under " Post a one-way frequency table (tabulate)" adds a horizontal line after Total - which is not a variable per se in the table.

    How can add one before "Observations" in a regression table? That is, is there a way to refer to the obversations line where var1 is in the varlabels command above?

    Here is a working example with sysuse auto:

    sysuse auto, clear

    eststo: reg price mpg trunk

    estadd scalar sum=_b[mpg]+_b[trunk]

    esttab using test.tex, booktabs scalars("sum Sum") obslast varlabels(, blist(N "\hline")) replace

    I want a horizontal line between "Sum" and "N" in the table. Here the varlabels option isn't actually doing anything....

    This is pretty in the weeds but if anyone could help it would stop my hourlong obsession with trying to figure this out


  • #2
    I dont know esttab, but you might edit the tex file using -filefilter-, Note the \W (Windows EOL):
    filefilter test.tex test2.tex , from("\BS(N\BS)") to("\BSmidrule\W\BS(N\BS)")
    Then, test2.tex have:
    Sum         &      -176.6         &      -176.6         \\
    \(N\)       &          74         &          74         \\


    • #3
      Amazing, this definitely worked. Thanks. Would be great if anyone still had a way to do it directly in esttab but this is nice and now I've learned about filefilter for doing any other crazy stuff I want to do!


      • #4
        As far as I can tell, there is no restriction on what you can include as a scalar in -esttab- and therefore, nothing stops you from being explicit

        esttab using test.tex, booktabs scalars("sum Sum" "k \hline") obslast replace
        Note that the "trick" here is that I define a non-existent scalar "k" whose display entry is the horizontal line.