Announcement

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

  • Exporting LaTeX regression table with 2 group classifications, using esttab

    I am using the command esttab in Stata to export a regression table. I would like to label my models with two different levels of group classification.

    So far I have the Stata code below:
    Code:
    sysuse auto, clear
    gen lowcost = (price<6000)
    
    reg price weight mpg if foreign==0 & lowcost==0
    est sto reg1
    reg price weight mpg if foreign==0 & lowcost==1
    est sto reg2
    reg price weight mpg if foreign==1 & lowcost==0
    est sto reg3
    reg price weight mpg if foreign==1 & lowcost==1
    est sto reg4
    
    local regressions reg1 reg2 reg3 reg4
    esttab `regressions' using "Latex/test.tex", replace mgroups("Domestic" "Foreign", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) mtitles("High-cost" "Low-cost" "High-cost" "Low-cost") nonumbers
    I would like to add another group classification for all the 4 models with the following label: "Outcome: Price". In my understanding, this would require us to add the following option to the esttab command above:

    Code:
    mgroups("Outcome: Price", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span)
    The problem is that esttab doesn't allow us to use the option -mgroups()- more than once. Does anyone have a solution to this?

    To see the tabel in LaTeX:

    Code:
    \documentclass{article}
    \begin{document}
        \input{test.tex}
    \end{document}

  • #2
    estout is from SSC (FAQ Advice #12). You can attempt to include this as a -prehead-

    Code:
    sysuse auto, clear
    gen lowcost = (price<6000)
    
    reg price weight mpg if foreign==0 & lowcost==0
    est sto reg1
    reg price weight mpg if foreign==0 & lowcost==1
    est sto reg2
    reg price weight mpg if foreign==1 & lowcost==0
    est sto reg3
    reg price weight mpg if foreign==1 & lowcost==1
    est sto reg4
    
    local regressions reg1 reg2 reg3 reg4
    
    esttab `regressions', replace prehead(&\multicolumn{4}{c}{Outcome: Price} \\) ///
    mgroups("Domestic" "Foreign", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
    mtitles("High-cost" "Low-cost" "High-cost" "Low-cost") nonumbers tex
    Res.:

    Code:
    . esttab `regressions', replace prehead(&\multicolumn{4}{c}{Outcome: Price} \\) ///
    > mgroups("Domestic" "Foreign", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
    > mtitles("High-cost" "Low-cost" "High-cost" "Low-cost") nonumbers tex
    
    &\multicolumn{4}{c}{Outcome: Price} \\
                &\multicolumn{2}{c}{Domestic}               &\multicolumn{2}{c}{Foreign}                \\
                &\multicolumn{1}{c}{High-cost}&\multicolumn{1}{c}{Low-cost}&\multicolumn{1}{c}{High-cost}&\multicolumn{1}{c}{Low-cost}\\
    \hline
    weight      &       3.885         &       0.828\sym{*}  &       4.763\sym{*}  &       1.870         \\
                &      (1.71)         &      (2.39)         &      (3.36)         &      (2.02)         \\
    [1em]
    mpg         &       175.7         &       23.98         &       11.64         &      -8.623         \\
                &      (0.56)         &      (0.53)         &      (0.07)         &     (-0.26)         \\
    [1em]
    \_cons      &     -8192.2         &      1502.7         &     -3848.0         &      1000.1         \\
                &     (-0.62)         &      (0.77)         &     (-0.54)         &      (0.39)         \\
    \hline
    \(N\)       &          14         &          38         &           9         &          13         \\
    \hline\hline
    \multicolumn{5}{l}{\footnotesize \textit{t} statistics in parentheses}\\
    \multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
    \end{tabular}
    }

    Comment


    • #3
      Many thanks Andrew Musau!

      I don't know why something seems wrong with the LaTeX code that is outputed from your code. For instance, I don't see
      Code:
      \begin{tabular}
      in the beginning of the tex code. Am I missing something?

      Many thanks again.

      Comment


      • #4
        Cross-posted at https://stackoverflow.com/questions/...s-using-esttab

        Please note our cross-posting policy, which is that you are asked to tell us about it. https://www.statalist.org/forums/help#crossposting

        Comment


        • #5
          May be a bug. Try adding:

          Code:
          esttab `regressions', replace prehead("\begin{tabular}{l*{@M}{r}}" "\hline \hline" "&\multicolumn{4}{c}{Outcome: Price} \\") ///
          mgroups("Domestic" "Foreign", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
          mtitles("High-cost" "Low-cost" "High-cost" "Low-cost") nonumbers tex
          Last edited by Andrew Musau; 20 Jun 2021, 15:26.

          Comment


          • #6
            Andrew Musau Thanks for your answers here! I have a quick clarification question; Say, I would like to run four more models for outcome "Tax" in addition to the previous Outcome "Price". Assume that all other things remain the same. How do I get four more columns to the right side of "Outcome: Price" that span under say "Outcome: Tax". I would still like to have mgroups("Domestic" "Foreign", pattern(1 0 1 0)) under "Outcome: Tax" and also still like to have mtitles("High-cost" "Low-cost" "High-cost" "Low-cost") under "Outcome: Tax". So I will have eight columns in total.
            Thanks a lot!
            Last edited by Steph Owusu; 02 Jun 2024, 07:09.

            Comment


            • #7
              We can recycle the same set of estimates in #2 to illustrate this. The following is not compiled, so you may have to adjust the column positions of the model groups. Otherwise, this should do it for what you want. Changes are highlighted.

              Code:
              sysuse auto, clear
              gen lowcost = (price<6000)
              
              reg price weight mpg if foreign==0 & lowcost==0
              est sto reg1
              reg price weight mpg if foreign==0 & lowcost==1
              est sto reg2
              reg price weight mpg if foreign==1 & lowcost==0
              est sto reg3
              reg price weight mpg if foreign==1 & lowcost==1
              est sto reg4
              
              local regressions reg1 reg2 reg3 reg4
              
              esttab `regressions' `regressions' using myfile.tex, replace prehead(&\multicolumn{4}{c}{Outcome: Price} &\multicolumn{8}{c}{Outcome: Tax}\\) ///
              mgroups("Domestic" "Foreign" "Domestic" "Foreign", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) ///
              mtitles("High-cost" "Low-cost" "High-cost" "Low-cost" "High-cost" "Low-cost" "High-cost" "Low-cost") nonumbers tex
              Res.:

              Code:
              &\multicolumn{4}{c}{Outcome: Price} &\multicolumn{8}{c}{Outcome: Tax}\\
              
              &\multicolumn{2}{c}{Domestic} &\multicolumn{2}{c}{Foreign} &\multicolumn{2}{c}{Domestic} &\multicolumn{2}{c}{Foreign} \\
              
              &\multicolumn{1}{c}{High-cost}&\multicolumn{1}{c}{Low-cost}&\multicolumn{1}{c}{High-cost}&\multicolumn{1}{c}{Low-cost}&\multicolumn{1}{c}{High-cost}&\multicolumn{1}{c}{Low-cost}&\multicolumn{1}{c}{High-cost}&\multicolumn{1}{c}{Low-cost}\\
              
              \hline
              
              weight & 3.885 & 0.828\sym{*} & 4.763\sym{*} & 1.870 & 3.885 & 0.828\sym{*} & 4.763\sym{*} & 1.870 \\
              
              & (1.71) & (2.39) & (3.36) & (2.02) & (1.71) & (2.39) & (3.36) & (2.02) \\
              
              [1em]
              
              mpg & 175.7 & 23.98 & 11.64 & -8.623 & 175.7 & 23.98 & 11.64 & -8.623 \\
              
              & (0.56) & (0.53) & (0.07) & (-0.26) & (0.56) & (0.53) & (0.07) & (-0.26) \\
              
              [1em]
              
              \_cons & -8192.2 & 1502.7 & -3848.0 & 1000.1 & -8192.2 & 1502.7 & -3848.0 & 1000.1 \\
              
              & (-0.62) & (0.77) & (-0.54) & (0.39) & (-0.62) & (0.77) & (-0.54) & (0.39) \\
              
              \hline
              
              \(N\) & 14 & 38 & 9 & 13 & 14 & 38 & 9 & 13 \\
              
              \hline\hline
              
              \multicolumn{9}{l}{\footnotesize \textit{t} statistics in parentheses}\\
              
              \multicolumn{9}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
              
              \end{tabular}
              
              }

              Comment


              • #8
                Thank you Andrew Musau. The only change I had to make to get me what I wanted is change &\multicolumn{8}{c}{Outcome: Tax} to &\multicolumn{4}{c}{Outcome: Tax}. This is how my code looks
                Code:
                 sysuse auto, clear
                gen lowcost = (price<6000)
                
                reg price weight mpg if foreign==0 & lowcost==0
                est sto reg1
                reg price weight mpg if foreign==0 & lowcost==1
                est sto reg2
                reg price weight mpg if foreign==1 & lowcost==0
                est sto reg3
                reg price weight mpg if foreign==1 & lowcost==1
                est sto reg4
                
                local regressions reg1 reg2 reg3 reg4
                
                esttab `regressions' `regressions' using myfile.tex, replace  prehead("\begin{tabular}{l*{@M}{r}}\hline \hline" "&\multicolumn{4}{c}{Outcome: Price} &\multicolumn{4}{c}{Outcome: Tax}\\") mgroups("Domestic" "Foreign" "Domestic" "Foreign", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) mtitles("High-cost" "Low-cost" "High-cost" "Low-cost" "High-cost" "Low-cost" "High-cost" "Low-cost") nonumbers tex

                Comment

                Working...
                X