Span multicolumn stats for LaTeX table with esttab/estout











up vote
3
down vote

favorite












I would like to be able to center a statistic over multiple columns when using esttab.



In my toy example, I would like N to span two columns:



sysuse auto, clear

est clear
qui estpost sum if foreign == 1
qui est store sum_foreign
qui estpost sum
qui est store sum_all

esttab sum_foreign sum_all, ///
replace ///
cells("mean(fmt(3)) sd(fmt(3))") ///
nonum ///
collabels("Mean" "SD") ///
label ///
noobs ///
drop(make) ///
stats(N, ///
fmt(%9.0fc) ///
label("Observations"))


Though the toy example just uses Stata's output, in general I would like to do this in LaTeX.



For other pieces of the table (collabels, mgroups etc.) you can specify the pattern() argument, which allows you to span, but this is not an option for stats().



Does anyone know how I can make the observation count span the width of the model (2 columns)?










share|improve this question




























    up vote
    3
    down vote

    favorite












    I would like to be able to center a statistic over multiple columns when using esttab.



    In my toy example, I would like N to span two columns:



    sysuse auto, clear

    est clear
    qui estpost sum if foreign == 1
    qui est store sum_foreign
    qui estpost sum
    qui est store sum_all

    esttab sum_foreign sum_all, ///
    replace ///
    cells("mean(fmt(3)) sd(fmt(3))") ///
    nonum ///
    collabels("Mean" "SD") ///
    label ///
    noobs ///
    drop(make) ///
    stats(N, ///
    fmt(%9.0fc) ///
    label("Observations"))


    Though the toy example just uses Stata's output, in general I would like to do this in LaTeX.



    For other pieces of the table (collabels, mgroups etc.) you can specify the pattern() argument, which allows you to span, but this is not an option for stats().



    Does anyone know how I can make the observation count span the width of the model (2 columns)?










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I would like to be able to center a statistic over multiple columns when using esttab.



      In my toy example, I would like N to span two columns:



      sysuse auto, clear

      est clear
      qui estpost sum if foreign == 1
      qui est store sum_foreign
      qui estpost sum
      qui est store sum_all

      esttab sum_foreign sum_all, ///
      replace ///
      cells("mean(fmt(3)) sd(fmt(3))") ///
      nonum ///
      collabels("Mean" "SD") ///
      label ///
      noobs ///
      drop(make) ///
      stats(N, ///
      fmt(%9.0fc) ///
      label("Observations"))


      Though the toy example just uses Stata's output, in general I would like to do this in LaTeX.



      For other pieces of the table (collabels, mgroups etc.) you can specify the pattern() argument, which allows you to span, but this is not an option for stats().



      Does anyone know how I can make the observation count span the width of the model (2 columns)?










      share|improve this question















      I would like to be able to center a statistic over multiple columns when using esttab.



      In my toy example, I would like N to span two columns:



      sysuse auto, clear

      est clear
      qui estpost sum if foreign == 1
      qui est store sum_foreign
      qui estpost sum
      qui est store sum_all

      esttab sum_foreign sum_all, ///
      replace ///
      cells("mean(fmt(3)) sd(fmt(3))") ///
      nonum ///
      collabels("Mean" "SD") ///
      label ///
      noobs ///
      drop(make) ///
      stats(N, ///
      fmt(%9.0fc) ///
      label("Observations"))


      Though the toy example just uses Stata's output, in general I would like to do this in LaTeX.



      For other pieces of the table (collabels, mgroups etc.) you can specify the pattern() argument, which allows you to span, but this is not an option for stats().



      Does anyone know how I can make the observation count span the width of the model (2 columns)?







      latex stata






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 18:54









      Pearly Spencer

      8,902163352




      8,902163352










      asked Nov 7 at 18:03









      Alexander Vornsand

      204




      204
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You need to manually insert the required spacing between each statistic with estadd, using the appropriate LaTeX markup as a prefix. This is necessary in order to typeset the table correctly.



          The following works for me:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 hspace{1.2cm}`e(N)'
          estadd local NA `N1'

          est store sum_foreign
          estpost sum

          local N2 hspace{2cm}`e(N)'
          estadd local NA `N2'

          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          stats(NA, ///
          fmt(%9.0fc) ///
          label("Observations"))




          EDIT:



          Here's another way of doing this but with automatic centering of the observation numbers:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N1'
          est store sum_foreign

          estpost sum

          local N2 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N2'
          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          postfoot("hline Observations: `N1' `N2' \ hlinehline \ end{tabular} \ }")





          share|improve this answer























          • Thanks for the suggestion, @Pearly Spencer. This seems like an okay approximation, but I'd like to find a solution that more precisely centers the statistic if it's possible (or is something that can be generalized).
            – Alexander Vornsand
            Nov 7 at 18:58










          • @AlexanderVornsand see the edit in my answer for a slightly more generalized solution.
            – Pearly Spencer
            Nov 7 at 22:18











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195216%2fspan-multicolumn-stats-for-latex-table-with-esttab-estout%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You need to manually insert the required spacing between each statistic with estadd, using the appropriate LaTeX markup as a prefix. This is necessary in order to typeset the table correctly.



          The following works for me:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 hspace{1.2cm}`e(N)'
          estadd local NA `N1'

          est store sum_foreign
          estpost sum

          local N2 hspace{2cm}`e(N)'
          estadd local NA `N2'

          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          stats(NA, ///
          fmt(%9.0fc) ///
          label("Observations"))




          EDIT:



          Here's another way of doing this but with automatic centering of the observation numbers:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N1'
          est store sum_foreign

          estpost sum

          local N2 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N2'
          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          postfoot("hline Observations: `N1' `N2' \ hlinehline \ end{tabular} \ }")





          share|improve this answer























          • Thanks for the suggestion, @Pearly Spencer. This seems like an okay approximation, but I'd like to find a solution that more precisely centers the statistic if it's possible (or is something that can be generalized).
            – Alexander Vornsand
            Nov 7 at 18:58










          • @AlexanderVornsand see the edit in my answer for a slightly more generalized solution.
            – Pearly Spencer
            Nov 7 at 22:18















          up vote
          1
          down vote



          accepted










          You need to manually insert the required spacing between each statistic with estadd, using the appropriate LaTeX markup as a prefix. This is necessary in order to typeset the table correctly.



          The following works for me:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 hspace{1.2cm}`e(N)'
          estadd local NA `N1'

          est store sum_foreign
          estpost sum

          local N2 hspace{2cm}`e(N)'
          estadd local NA `N2'

          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          stats(NA, ///
          fmt(%9.0fc) ///
          label("Observations"))




          EDIT:



          Here's another way of doing this but with automatic centering of the observation numbers:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N1'
          est store sum_foreign

          estpost sum

          local N2 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N2'
          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          postfoot("hline Observations: `N1' `N2' \ hlinehline \ end{tabular} \ }")





          share|improve this answer























          • Thanks for the suggestion, @Pearly Spencer. This seems like an okay approximation, but I'd like to find a solution that more precisely centers the statistic if it's possible (or is something that can be generalized).
            – Alexander Vornsand
            Nov 7 at 18:58










          • @AlexanderVornsand see the edit in my answer for a slightly more generalized solution.
            – Pearly Spencer
            Nov 7 at 22:18













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You need to manually insert the required spacing between each statistic with estadd, using the appropriate LaTeX markup as a prefix. This is necessary in order to typeset the table correctly.



          The following works for me:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 hspace{1.2cm}`e(N)'
          estadd local NA `N1'

          est store sum_foreign
          estpost sum

          local N2 hspace{2cm}`e(N)'
          estadd local NA `N2'

          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          stats(NA, ///
          fmt(%9.0fc) ///
          label("Observations"))




          EDIT:



          Here's another way of doing this but with automatic centering of the observation numbers:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N1'
          est store sum_foreign

          estpost sum

          local N2 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N2'
          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          postfoot("hline Observations: `N1' `N2' \ hlinehline \ end{tabular} \ }")





          share|improve this answer














          You need to manually insert the required spacing between each statistic with estadd, using the appropriate LaTeX markup as a prefix. This is necessary in order to typeset the table correctly.



          The following works for me:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 hspace{1.2cm}`e(N)'
          estadd local NA `N1'

          est store sum_foreign
          estpost sum

          local N2 hspace{2cm}`e(N)'
          estadd local NA `N2'

          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          stats(NA, ///
          fmt(%9.0fc) ///
          label("Observations"))




          EDIT:



          Here's another way of doing this but with automatic centering of the observation numbers:



          sysuse auto, clear

          est clear
          estpost sum if foreign == 1

          local N1 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N1'
          est store sum_foreign

          estpost sum

          local N2 &multicolumn{2}{c}{`e(N)'}

          estadd local NA `N2'
          est store sum_all

          esttab sum_foreign sum_all using table.tex, ///
          replace ///
          cells("mean(fmt(3)) sd(fmt(3))") ///
          nonum ///
          collabels("Mean" "SD") ///
          label ///
          noobs ///
          drop(make) ///
          postfoot("hline Observations: `N1' `N2' \ hlinehline \ end{tabular} \ }")






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 7 at 22:17

























          answered Nov 7 at 18:41









          Pearly Spencer

          8,902163352




          8,902163352












          • Thanks for the suggestion, @Pearly Spencer. This seems like an okay approximation, but I'd like to find a solution that more precisely centers the statistic if it's possible (or is something that can be generalized).
            – Alexander Vornsand
            Nov 7 at 18:58










          • @AlexanderVornsand see the edit in my answer for a slightly more generalized solution.
            – Pearly Spencer
            Nov 7 at 22:18


















          • Thanks for the suggestion, @Pearly Spencer. This seems like an okay approximation, but I'd like to find a solution that more precisely centers the statistic if it's possible (or is something that can be generalized).
            – Alexander Vornsand
            Nov 7 at 18:58










          • @AlexanderVornsand see the edit in my answer for a slightly more generalized solution.
            – Pearly Spencer
            Nov 7 at 22:18
















          Thanks for the suggestion, @Pearly Spencer. This seems like an okay approximation, but I'd like to find a solution that more precisely centers the statistic if it's possible (or is something that can be generalized).
          – Alexander Vornsand
          Nov 7 at 18:58




          Thanks for the suggestion, @Pearly Spencer. This seems like an okay approximation, but I'd like to find a solution that more precisely centers the statistic if it's possible (or is something that can be generalized).
          – Alexander Vornsand
          Nov 7 at 18:58












          @AlexanderVornsand see the edit in my answer for a slightly more generalized solution.
          – Pearly Spencer
          Nov 7 at 22:18




          @AlexanderVornsand see the edit in my answer for a slightly more generalized solution.
          – Pearly Spencer
          Nov 7 at 22:18


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195216%2fspan-multicolumn-stats-for-latex-table-with-esttab-estout%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings