Announcement

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

  • estpost/esttab: Adding sample sizes to the table?

    Dear Statalisteners,

    I want to make a descriptive table using -esttab- (from SSC), broken down by subgroups, like this:

    Code:
    sysuse auto, clear
    
    estpost tabstat trunk weight length, by(foreign) statistics(mean sd) columns(statistics)
    
    esttab, cells(mean(fmt(2)) sd(fmt(2) par)) unstack nomtitle nonumbers
    This gives me a table like this:

    Code:
    ---------------------------------------------------
                     Domestic      Foreign        Total
                      mean/sd      mean/sd      mean/sd
    ---------------------------------------------------
    trunk               14.75        11.41        13.76
                       (4.31)       (3.22)       (4.28)
    weight            3317.12      2315.91      3019.46
                     (695.36)     (433.00)     (777.19)
    length             196.13       168.55       187.93
                      (20.05)      (13.68)      (22.27)
    ---------------------------------------------------
    N                      74                          
    ---------------------------------------------------
    This is great, but I am unhappy with the bottom line giving the N. I know that I can suppress it with

    Code:
    esttab, cells(mean(fmt(2)) sd(fmt(2) par)) unstack nomtitle nonumbers noobs
    But what I would rather have is a bottom line that gives me the N of the groups, kind of like this

    Code:
    ---------------------------------------------------
                     Domestic      Foreign        Total
                      mean/sd      mean/sd      mean/sd
    ---------------------------------------------------
    trunk               14.75        11.41        13.76
                       (4.31)       (3.22)       (4.28)
    weight            3317.12      2315.91      3019.46
                     (695.36)     (433.00)     (777.19)
    length             196.13       168.55       187.93
                      (20.05)      (13.68)      (22.27)
    ---------------------------------------------------
    N                      52         22          74
    ---------------------------------------------------
    Is there a way to achieve that?

    Many thanks for your consideration
    Go

  • #2
    estout is from the Stata Journal/SSC, as you are asked to explain (FAQ Advice #12). Thanks for the data example. The fact that you unstack the categories does not mean that you have 3 sets of estimation results. If you want 3 different statistics, you need to have 3 different models.

    Code:
    sysuse auto, clear
    eststo m1: estpost tabstat trunk weight length if !foreign, statistics(mean sd) columns(statistics)
    eststo m2: estpost tabstat trunk weight length if foreign, statistics(mean sd) columns(statistics)
    eststo m3: estpost tabstat trunk weight length, statistics(mean sd) columns(statistics)
    esttab, cells(mean(fmt(2)) sd(fmt(2) par)) unstack nonumbers noobs ///
    stats(N, fmt(a)) mtitles("Domestic" "Foreign" "Total")
    Res.:

    Code:
    . esttab, cells(mean(fmt(2)) sd(fmt(2) par)) unstack nonumbers noobs ///
    > stats(N, fmt(a)) mtitles("Domestic" "Foreign" "Total")
    
    ---------------------------------------------------
                     Domestic      Foreign        Total
                      mean/sd      mean/sd      mean/sd
    ---------------------------------------------------
    trunk               14.75        11.41        13.76
                       (4.31)       (3.22)       (4.28)
    weight            3317.12      2315.91      3019.46
                     (695.36)     (433.00)     (777.19)
    length             196.13       168.55       187.93
                      (20.05)      (13.68)      (22.27)
    ---------------------------------------------------
    N                      52           22           74
    ---------------------------------------------------

    Comment


    • #3
      Oh wow, thanks, that is great! I didn't know that it's possible to combine estpost with eststo.

      Comment


      • #4
        Hello!

        I have a similar problem, but even with the help on this forum I can't figure it out. I want to export the following table to word (excel would also be fine):

        Code:
                Year | e(EMDea~)  e(DMDea~)  e(DealO~)  e(EMExi~)  e(EMExi~)  e(EMIPO~)  e(DMExi~)  e(DMExi~)  e(DMIPO~) 
        -------------+---------------------------------------------------------------------------------------------------
                1990 |         2        124        126          0          0          0         81          5         50 
                1991 |         0        146        146          0          0          0         93          6         59 
                1992 |         5        178        183          3          0          0        114          5         69 
                1993 |        14        196        210          3          0          1        124         16         75 
                1994 |        21        248        269         10          0          4        167         15         99 
                1995 |        27        342        369         14          2          6        240         31        132 
                1996 |        33        419        452         24          0         10        303         34        172 
                1997 |        34        517        551         22          1         11        367         41        193 
                1998 |        61        660        721         36          2         15        448         53        256 
                1999 |        73        922        995         43          5         23        601         51        283 
                2000 |        66       1017       1083         38          5         21        705         44        391 
                2001 |        47        795        842         31          2         14        547         32        276 
                2002 |        50        969       1019         35          3         22        655         44        334 
                2003 |        97       1225       1322         58          9         25        829        112        425 
                2004 |       112       1617       1729         62         10         29       1072        149        531 
                2005 |       188       2169       2357         92          7         44       1354        176        687 
                2006 |       326       3040       3366        156         25         80       1577        163        810 
                2007 |       556       3488       4044        236         20        114       1810        139        908 
                2008 |       477       2846       3323        182         24         90       1313         89        691 
                2009 |       369       2013       2382        128         22         74        785         84        453 
                2010 |       564       2946       3510        147         20         75       1189         91        657 
                2011 |       695       3501       4196        161         18         90       1209        115        621 
                2012 |       663       3647       4310        132         18         64       1171        104        613 
                2013 |       585       3446       4031        110         20         61        914        100        516 
                2014 |       602       4252       4854        100         18         55       1008        140        575 
                2015 |       535       4556       5091         62         12         35        841        161        495 
                2016 |       556       4851       5407         45         14         27        688        200        404 
                2017 |       536       5307       5843         28          8         14        433        171        265 
                2018 |       517       5775       6292         12          8          7        220        128        163 
        -------------+---------------------------------------------------------------------------------------------------
               Total |      7811      61212      69023       1970        273       1011      20858       2499      11203
        I just don't see what I am doing wrong, have been struggling with this for over 2 days now... Tried many different codes but nothing works. This is the code I used last:

        Code:
        by Year: egen EMDealObs = count(Deal) if EmergingMarket == 1
        eststo D1: estpost tabstat EMDealObs, by(Year) stats(n)
        
        by Year: egen DMDealObs = count(Deal) if EmergingMarket == 0
        eststo D2: estpost tabstat EMDealObs DMDealObs, by(Year) stats(n)
        
        by Year: egen DealObs = count(Deal)
        eststo D3: estpost tabstat EMDealObs DMDealObs DealObs, by(Year) stats(n)
        
        by Year: egen EMExitObs = count(Exit) if Exit == 1 & EmergingMarket == 1
        eststo D4: estpost tabstat EMDealObs DMDealObs DealObs EMExitObs, by(Year) stats(n)
        
        by Year: egen EMExit2Obs = count(Exit2) if Exit2 == 1 & EmergingMarket == 1
        eststo D5: estpost tabstat EMDealObs DMDealObs DealObs EMExitObs EMExit2Obs, by(Year) stats(n)
        
        by Year: egen EMIPOMAObs = count(IPO_MA) if IPO_MA == 1 & EmergingMarket == 1
        eststo D6: estpost tabstat EMDealObs DMDealObs DealObs EMExitObs EMExit2Obs EMIPOMAObs, by(Year) stats(n)
        
        by Year: egen DMExitObs = count(Exit) if Exit == 1 & EmergingMarket == 0
        eststo D7: estpost tabstat EMDealObs DMDealObs DealObs EMExitObs EMExit2Obs EMIPOMAObs DMExitObs, by(Year) stats(n)
        
        by Year: egen DMExit2Obs = count(Exit2) if Exit2 == 1 & EmergingMarket == 0
        eststo D8: estpost tabstat EMDealObs DMDealObs DealObs EMExitObs EMExit2Obs EMIPOMAObs DMExitObs DMExit2Obs, by(Year) stats(n)
        
        by Year: egen DMIPOMAObs = count(IPO_MA) if IPO_MA == 1 & EmergingMarket == 0
        eststo D9: estpost tabstat EMDealObs DMDealObs DealObs EMExitObs EMExit2Obs EMIPOMAObs DMExitObs DMExit2Obs DMIPOMAObs, by(Year) stats(n)
        esttab D1 D2 D3 D4 D5 D6 D7 D8 D9 using SumStats.rtf, replace
        But in word it returns this:
        (1) (2) (3) (4) (5) (6) (7) (8) (9)
        N 7811 69023 69023 69023 69023 69023 69023 69023 69023
        t statistics in parentheses
        * p < 0.05, ** p < 0.01, *** p < 0.001





        Isn't even close to what I want.. Can somebody help me please?

        P.S. Sorry if my post is unclear, first post on Statalist.


        Comment


        • #5
          Store the statistics one by one and then output them at one go. The command stores frequencies as e(count). Here is an example:

          Code:
          set obs 2000
          set seed 05312021
          gen Year=runiformint(1998, 2018)
          gen Deal= "yes"
          gen EmergingMarket = runiformint(0,1)
          gen Exit = runiformint(0,1)
          
          *START HERE
          bys Year: egen EMDealObs = count(Deal) if EmergingMarket == 1
          bys Year: egen DMDealObs = count(Deal) if EmergingMarket == 0
          bys Year: egen DealObs = count(Deal)
          bys Year: egen EMExitObs = count(Exit) if Exit == 1 & EmergingMarket == 1
          local i 1
          foreach var in EMDealObs DMDealObs DealObs EMExitObs{
              eststo D`i': estpost tabstat `var', by(Year) stats(n)
              local ++i
          }
          esttab, cells(count) nonum noobs stats(N) mtitles(EMDeal DMDeal Deal EMExit) collab(none) drop(Total)
          Res.:

          Code:
          . esttab, cells(count) nonum noobs stats(N) mtitles(EMDeal DMDeal Deal EMExit) collab(none
          > ) drop(Total)
          
          ----------------------------------------------------------------
                             EMDeal       DMDeal         Deal       EMExit
          ----------------------------------------------------------------
          1998                   49           46           95           19
          1999                   51           32           83           26
          2000                   51           42           93           24
          2001                   53           52          105           27
          2002                   45           31           76           25
          2003                   55           37           92           14
          2004                   55           44           99           33
          2005                   34           61           95           17
          2006                   43           60          103           20
          2007                   45           56          101           27
          2008                   56           51          107           28
          2009                   45           35           80           24
          2010                   42           48           90           19
          2011                   35           61           96           16
          2012                   51           42           93           23
          2013                   53           33           86           31
          2014                   62           45          107           31
          2015                   56           42           98           27
          2016                   51           49          100           32
          2017                   56           51          107           31
          2018                   45           49           94           24
          ----------------------------------------------------------------
          N                    1033          967         2000          518
          ----------------------------------------------------------------

          Comment


          • #6
            Andrew, has anyone told you yet that you are a legend?! Thank you very much, it worked!

            Here's the result if you're interested:
            Year Buyout Deals Emerging Markets Developed Markets
            EMs DMs Full sample Total exits Within 2 years Through IPO or M&A Total exits Within 2 years Through IPO or M&A
            1990 2 124 126 0 0 0 81 5 50
            1991 0 146 146 0 0 0 93 6 59
            1992 5 178 183 3 0 0 114 5 69
            1993 14 196 210 3 0 1 124 16 75
            1994 21 248 269 10 0 4 167 15 99
            1995 27 342 369 14 2 6 240 31 132
            1996 33 419 452 24 0 10 303 34 172
            1997 34 517 551 22 1 11 367 41 193
            1998 61 660 721 36 2 15 448 53 256
            1999 73 922 995 43 5 23 601 51 283
            2000 66 1017 1083 38 5 21 705 44 391
            2001 47 795 842 31 2 14 547 32 276
            2002 50 969 1019 35 3 22 655 44 334
            2003 97 1225 1322 58 9 25 829 112 425
            2004 112 1617 1729 62 10 29 1072 149 531
            2005 188 2169 2357 92 7 44 1354 176 687
            2006 326 3040 3366 156 25 80 1577 163 810
            2007 556 3488 4044 236 20 114 1810 139 908
            2008 477 2846 3323 182 24 90 1313 89 691
            2009 369 2013 2382 128 22 74 785 84 453
            2010 564 2946 3510 147 20 75 1189 91 657
            2011 695 3501 4196 161 18 90 1209 115 621
            2012 663 3647 4310 132 18 64 1171 104 613
            2013 585 3446 4031 110 20 61 914 100 516
            2014 602 4252 4854 100 18 55 1008 140 575
            2015 535 4556 5091 62 12 35 841 161 495
            2016 556 4851 5407 45 14 27 688 200 404
            2017 536 5307 5843 28 8 14 433 171 265
            2018 517 5775 6292 12 8 7 220 128 163
            7811 61212 69023 1970 273 1011 20858 2499 11203
            (It looks much nicer in Word, but no idea how to input that in here haha)

            Thanks a lot Andrew!

            Comment

            Working...
            X