Announcement

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

  • Descriptive statistics esttab options

    Hello, still very new to Stata and I'm trying to create a clean table output.

    This is the code I've used so far:
    estpost varlist
    eststo descriptive

    esttab descriptive ///
    using "/FileLocation.rtf", ///
    cells("N mean sd") label ti("Variable Definitions and Descriptive Statistics") ///
    varwidth(10) replace

    This gives me a column for N, mean, and sd.
    How do I get the mean and sd to abbreviate to two decimal points instead of 6? And if I wanted the sd under the mean instead of its own column, how could I change that?

    Thank you.

  • #2
    estout is from SSC (FAQ Advice #12).

    Code:
    sysuse auto, clear
    estpost sum mpg weight disp
    esttab, label cell(mean(fmt(2)) sd(par(( ))))  unstack varwidth(30) ///
    nonum collab(none) noobs mlab("Mean (SD)",lhs("Variables"))
    Res.:

    Code:
    
    . esttab, label cell(mean(fmt(2)) sd(par(( ))))  unstack varwidth(30) ///
    > nonum collab(none) noobs mlab("Mean (SD)",lhs("Variables"))
    
    -------------------------------------------
    Variables                         Mean (SD)
    -------------------------------------------
    Mileage (mpg)                         21.30
                                         (5.79)
    Weight (lbs.)                       3019.46
                                       (777.19)
    Displacement (cu. in.)               197.30
                                        (91.84)
    -------------------------------------------

    Comment


    • #3
      Thank you! That's almost exactly what I'm looking for. How do I also get a column for number of observations?

      Comment


      • #4
        See https://www.statalist.org/forums/for...rs-with-esttab

        Comment


        • #5
          Andrew, I appreciate it, but I can't make heads or tales of that.

          Is there some easy change to this code:
          esttab descriptive ///
          using "/filename", ///
          cells("count mean sd(par(( )))") label ti("Variable Definitions and Descriptive Statistics") ///
          varwidth(10) replace

          ...that will make the mean and sd two decimal points?

          OR, is there an easy change to this code:
          esttab descriptive ///
          using "/filename", ///
          label cells (mean(fmt(2)) sd(par(( )))) unstack varwidth(30) ///
          nonum collab(none) noobs mlab("Mean (SD)",lhs("Variables")) replace

          ...that will add the number of observations AND set the sd *next to* the mean instead of underneath it?

          Thank you.

          Comment


          • #6
            Pay attention to the use of quotation marks.

            Code:
            sysuse auto, clear
            estpost sum mpg weight disp
            esttab, label cell("mean(fmt(2)) sd(par(( )))" count(par([ ]) fmt(0)))  unstack varwidth(30) ///
            nonum collab(none) noobs mlab("Mean (SD) [Obs.]",lhs("Variables")) noabbrev
            Res.:

            Code:
            . esttab, label cell("mean(fmt(2)) sd(par(( )))" count(par([ ]) fmt(0)))  unstack varwidth(30) ///
            > nonum collab(none) noobs mlab("Mean (SD) [Obs.]",lhs("Variables")) noabbrev
            
            --------------------------------------------------------
            Variables                      Mean (SD) [Obs.]             
            --------------------------------------------------------
            Mileage (mpg)                         21.30       (5.79)
                                                   [74]             
            Weight (lbs.)                       3019.46     (777.19)
                                                   [74]             
            Displacement (cu. in.)               197.30      (91.84)
                                                   [74]             
            --------------------------------------------------------
            PS. On tales and tails, see https://www.thoughtco.com/tail-and-tale-1689503

            Comment


            • #7
              Andrew, that helps. I'll work with that today.

              And on tails/tales, that just shows you how addled my brain is that I didn't catch that. Definitely smacking my forehead on that one.

              Comment


              • #8
                Originally posted by Joshua Dalton View Post
                And on tails/tales, that just shows you how addled my brain is that I didn't catch that. Definitely smacking my forehead on that one.
                It happens to the best of us! Also note that everything in one row is possible by including all contents within cell in quotation marks.

                Code:
                sysuse auto, clear
                estpost sum mpg weight disp
                esttab, label cell("mean(fmt(2)) sd(par(( ))) count(par([ ]) fmt(0))") unstack varwidth(30) ///
                nonum collab(none) noobs mlab("Mean (SD) [Obs.]",lhs("Variables")) noabbrev
                Res.:

                Code:
                . esttab, label cell("mean(fmt(2)) sd(par(( ))) count(par([ ]) fmt(0))") unstack varwidth(30) ///
                > nonum collab(none) noobs mlab("Mean (SD) [Obs.]",lhs("Variables")) noabbrev
                
                ---------------------------------------------------------------------
                Variables                      Mean (SD) [Obs.]                          
                ---------------------------------------------------------------------
                Mileage (mpg)                         21.30       (5.79)         [74]
                Weight (lbs.)                       3019.46     (777.19)         [74]
                Displacement (cu. in.)               197.30      (91.84)         [74]
                ---------------------------------------------------------------------
                If the parentheses and brackets are not desirable, then

                Code:
                sysuse auto, clear
                estpost sum mpg weight disp
                esttab, label cell("mean(fmt(2)) sd count(fmt(0))") unstack varwidth(30) ///
                nonum collab(none) noobs mlab("Mean SD Obs.",lhs("Variables")) noabbrev
                Res.:

                Code:
                . esttab, label cell("mean(fmt(2)) sd count(fmt(0))") unstack varwidth(30) ///
                > nonum collab(none) noobs mlab("Mean SD Obs.",lhs("Variables")) noabbrev
                
                ---------------------------------------------------------------------
                Variables                      Mean SD Obs.                          
                ---------------------------------------------------------------------
                Mileage (mpg)                         21.30         5.79           74
                Weight (lbs.)                       3019.46       777.19           74
                Displacement (cu. in.)               197.30        91.84           74
                ---------------------------------------------------------------------

                Comment


                • #9
                  That makes so much sense. Thank you for explaining it. I just wasn't seeing the meaning behind the syntax.

                  One more question to make use of your obvious expertise: Say I had the following code for a table of a series of regression results:

                  esttab [varlist] ///
                  using "[location]", ///
                  b(3) star(* .1 ** .05 *** .01) se(3) pr2 ///
                  compress varwidth(30) label lines nogaps obslast drop(0.*) ///
                  ti("Title") unstack r ///
                  mtitles("[varlist]")

                  It gives me a nice table with the series of DV's across the top and IV's along the side. But say I wanted those reversed. Any idea how I would amend the code to swap those?

                  Comment


                  • #10
                    Ben Jann shows how to do this under "Flip models and coefficients (place models in rows instead of in columns)" .
                    Last edited by Andrew Musau; 14 Sep 2022, 02:10.

                    Comment

                    Working...
                    X