Announcement

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

  • Putting the title in the center when using esttab for two-way tabulation


    Hello Statalist users, I am using estpost and esttab to generate a table using two-way tabulate. sysuse auto, clear estpost tabulate rep78 foreign esttab ., cell("b colpct(fmt(2))") unstack noobs ------------------------------------------------------------------------------------------ (1) Domestic Foreign Total b colpct b colpct b colpct ------------------------------------------------------------------------------------------ 1 2 4.17 0 0.00 2 2.90 2 8 16.67 0 0.00 8 11.59 3 27 56.25 3 14.29 30 43.48 4 9 18.75 9 42.86 18 26.09 5 2 4.17 9 42.86 11 15.94 Total 48 100.00 21 100.00 69 100.00 ------------------------------------------------------------------------------------------ I want to put "Domestic" and "Foreign" in the center, while getting rid of colpct for Total. Can you help me how to solve this? Thank you so much!

  • #2
    The output is awful. Sorry for the confusion.

    sysuse auto,
    clear estpost tabulate rep78 foreign
    esttab ., cell("b colpct(fmt(2))") unstack noobs


    ------------------------------------------------------------------------------------------
    (1)

    Domestic Foreign Total
    b colpct b colpct b colpct
    ------------------------------------------------------------------------------------------
    1 2 4.17 0 0.00 2 2.90
    2 8 16.67 0 0.00 8 11.59
    3 27 56.25 3 14.29 30 43.48
    4 9 18.75 9 42.86 18 26.09
    5 2 4.17 9 42.86 11 15.94
    Total 48 100.00 21 100.00 69 100.00
    ------------------------------------------------------------------------------------------



    I want to put "Domestic" and "Foreign" in the center, while getting rid of colpct for Total. Can you help me how to solve this? Thank you so much!

    Comment


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

      I want to put "Domestic" and "Foreign" in the center
      You can do it in a LaTeX table, see #8 of https://www.statalist.org/forums/for...rs-with-esttab.

      while getting rid of colpct for Total
      You need to output the results as separate models to specify different options.

      sysuse auto,clear
      estpost tabulate rep78 foreign
      becomes

      Code:
      sysuse auto,clear
      forval i=1/3{
          local cond= cond(`i'==1, "if !foreign", cond(`i'==2, "if foreign", ""))
          eststo m`i': estpost tabulate rep78 `cond'
      }
      esttab m*, cell("b(pattern(1 1 1)) pct(pattern(1 1 0) fmt(2))") noobs nomtitles eqlab(none)
      Res.:

      Code:
      . esttab m*, cell("b(pattern(1 1 1)) pct(pattern(1 1 0) fmt(2))") noobs nomtitles eqlab(none)
      
      -----------------------------------------------------------------------------
                            (1)                       (2)                       (3)
                              b          pct            b          pct            b
      -----------------------------------------------------------------------------
      1                       2         4.17                                      2
      2                       8        16.67                                      8
      3                      27        56.25            3        14.29           30
      4                       9        18.75            9        42.86           18
      5                       2         4.17            9        42.86           11
      Total                  48       100.00           21       100.00           69
      -----------------------------------------------------------------------------

      Comment


      • #4
        Hi Andrew,

        Thanks for your reply. I will dig into your post.

        Comment

        Working...
        X