Announcement

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

  • labelling rows and columns of summary statistics with esttab

    I am producing tables of summary statistics with -esttab-, from -ssc-, in Stata 14. Each statistic is in its own row, like in the following:

    Code:
    sysuse auto, clear
    estimates clear
    eststo: estpost su mpg
    esttab, cells(mean(fmt(2)) sd(fmt(2)) count(label(N) fmt(0)))
    The output table looks like this:

    Code:
    -------------------------
                          (1)
                            
                    mean/sd/N
    -------------------------
    mpg                 21.30
                         5.79
                           74
    -------------------------
    N                      74
    -------------------------
    Question 1: How do I swap the variable name, mpg, and the names of the statistics, so that furthermore each statistic name is in its own row?
    Question 2: How do I make the column number appear below all other model or group titles or column labels? I found this analogous question on statalist, but seemingly no answer.

    My ideal table would look something like this:

    Code:
    -------------------------
                            
                         mpg
                          (1)
    -------------------------
    mean           21.30
    SD                 5.79
    N                       74
    -------------------------
    N                      74
    -------------------------

    Thanks for all your help.

  • #2
    Did you find a solution?

    Comment


    • #3
      Is this what you are looking for?

      Code:
      esttab, cells(mean(fmt(2)) sd(fmt(2)) count(label(N) fmt(0))) label replace

      Comment


      • #4
        I am sorry, the code in #3 is not what you were looking for. I posted prematurely (and it takes forever to wait for editing the post).

        Comment


        • #5
          This thread was started nearly five years ago, but the most recent response was just a few days ago. Here, you can define a new matrix for the results to achieve the intended format in #1. Use of -collab()- and -mlab()- can fix the numbering issue. -noobs- eliminates the duplication of observation counts.

          Code:
          sysuse auto, clear
          estimates clear
          eststo m1: estpost su mpg
          mat wanted= e(mean)\ e(sd)\ e(count)
          mat rownames wanted = mean sd N
          estadd mat wanted= wanted': m1
          esttab, cells(wanted) mlab(mpg) collab((1)) nonumb noobs
          Res.:

          Code:
          . esttab, cells(wanted) mlab(mpg) collab((1)) nonumb noobs
          
          -------------------------
                                mpg
                                (1)
          -------------------------
          mean              21.2973
          sd               5.785503
          N                      74
          -------------------------
          Last edited by Andrew Musau; 06 Feb 2025, 04:43.

          Comment


          • #6
            Thanks for the responses, I don't even remember what I ended up doing at the time, but Andrew's solution certainly delivers what I was asking for.

            Comment

            Working...
            X