Announcement

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

  • Drop top row with variable names/labels when outputting correlation matrix with esstab

    I am outputting a correlation matrix into a .tex file, to present as a table in Latex. I'm using estpost to do it, following posts by others. I want to use the variable labels in the left-hand row titles, hence my use of the label option in esttab. However, I would like to SEPARATELY control the row that is automatically created as column titles, because the labels are far too long. (Oddly, they are not actually column titles, as in mtitles, they are below the mtitles.)

    Here is a reproducible example. Code:
    PHP Code:
    sysuse autoclear
    estpost corr price mpg headroom weight length
    matrix
    esttab using 
    "${TABLES}/Tab_CorrMat1.tex"unstack noobs nonum cells(rho(fmt(2))) collabels(""label replace fragment mtitle("About this correlation matrix"
    It creates a .tex file with this content:
    PHP Code:
                        &\multicolumn{5}{c}{About this correlation matrix}               \\
                        &       
    Price&Mileage (mpg)&Headroom (in.)&Weight (lbs.)&Length (in.)\\
                        &            &            &            &            &            \\
    \
    hline
    Price               
    &        1.00&            &            &            &            \\
    Mileage (mpg)       &       -0.47&        1.00&            &            &            \\
    Headroom (in.)      &        0.11&       -0.41&        1.00&            &            \\
    Weight (lbs.)       &        0.54&       -0.81&        0.48&        1.00&            \\
    Length (in.)        &        0.43&       -0.80&        0.52&        0.95&        1.00\\ 

    While I can delete the top row by adding "nomtitle" to the options in esttab, what I'd LIKE to delete is the second two lines, "& Price&Mileage (mpg)&Headroom (in.)&Weight (lbs.)&Length (in.)\\" and the empty line after it.
    Last edited by Leah Bevis; 14 Apr 2022, 15:30.

  • #2
    estout is from SSC (FAQ Advice #12). Thanks for the reproducible example. The empty row is as a result of specifying

    Code:
    collabels("")
    You need instead

    Code:
    collabels(none)
    The other row contains equation labels. So in all, you want

    Code:
    sysuse auto, clear
    estpost corr price mpg headroom weight length, matrix
    esttab, unstack noobs nonum cells(rho(fmt(2))) collabels(none)  eqlab(none) label replace fragment mtitle("About this correlation matrix") tex
    Res.:

    Code:
    . esttab, unstack noobs nonum cells(rho(fmt(2))) collabels(none)  eqlab(none) label replace fragment mtitle("About this correlation matr
    > ix") tex
    
                        &\multicolumn{5}{c}{About this correlation matrix}               \\
    \hline
    Price               &        1.00&            &            &            &            \\
    Mileage (mpg)       &       -0.47&        1.00&            &            &            \\
    Headroom (in.)      &        0.11&       -0.41&        1.00&            &            \\
    Weight (lbs.)       &        0.54&       -0.81&        0.48&        1.00&            \\
    Length (in.)        &        0.43&       -0.80&        0.52&        0.95&        1.00\\

    Comment


    • #3
      This is amazing, tank you so much! I should have seen the collabel() thing. But I don't think I was going to get the eqlab() bit, I didn't realize that's what the row was for. Thanks again!

      Comment

      Working...
      X