Announcement

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

  • Estout matrix - super column names

    I have exactly the same situation as this one: http://www.stata.com/statalist/archi.../msg00023.html

    The problem is that when trying to export the table in .tex, esttab only creates 3 columns in \tabular{}, instead of the 5 that are needed.

    I re-type the code suggested as a solution, and the corresponding .tex file.

    Code:
    mat A = (1,2,3,4)
    mat coln A = male:1979 male:2007 female:1979 female:2007
    mat rown A = mystat
    mat tmp = A[1...,"male:"]'
    ereturn post
    estadd matrix A = tmp
    eststo male
    mat tmp = A[1...,"female:"]'
    ereturn post
    estadd matrix A = tmp
    eststo female
    estout male female using test.tex, cell((A["1979"] A["2007"]))
    The .tex file generated is:

    Code:
    {
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
    \begin{tabular}{l*{2}{c}}
    \hline\hline
                &\multicolumn{2}{c}{(1)}  &\multicolumn{2}{c}{(2)}  \\
                &\multicolumn{2}{c}{}     &\multicolumn{2}{c}{}     \\
                &        1979&        2007&        1979&        2007\\
    \hline
    mystat      &           1&           2&           3&           4\\
    \hline
    \(N\)       &            &            &            &            \\
    \hline\hline
    \end{tabular}
    }
    How can I tell esttab that I actually need more than one column per model in the .tex file?

    Thanks!

  • #2
    I don't know how to fix this the right way, but I can show you a kludge.

    Firstly, you appear to be running -esttab-, not -estout-. If you use -estout-, you won't have this problem, because you'll be compelled to add the window dressing yourself. Alternatively, add the -esttab, noisily- option to see the internal -estout- command:
    Code:
    . esttab male female, cell((A["1979"] A["2007"])) tex noisily
    estout male female ,
     cells((A["1979"] A["2007"]))
     stats(N, fmt(%18.0g) labels(`"\(N\)"'))
     starlevels(\sym{*} 0.05 \sym{**} 0.01 \sym{***} 0.001, label(" \(p<@\)"))
     varwidth(12)
     modelwidth(12)
     delimiter(&)
     end(\\)
     prehead(`"{"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' `"\begin{tabular}{l*{@E}{c}}"' `"\hline\hline"')
     posthead("\hline")
     prefoot("\hline")
     postfoot(`"\hline\hline"' `"\end{tabular}"' `"}"')
     mlabels(, depvar span prefix(\multicolumn{@span}{c}{) suffix(}))
     numbers(\multicolumn{@span}{c}{( )})
     eqlabels(, begin("\hline" "") nofirst)
     substitute(_ \_ "\_cons " \_cons)
     interaction(" $\times$ ")
     level(95)
     style(esttab)
    The part that's screwing up your table is \begin{tabular}{l*{@E}{c}}. Run the -estout- command, except replace @E with 4:
    Code:
    estout male female ,
     cells((A["1979"] A["2007"]))
     stats(N, fmt(%18.0g) labels(`"\(N\)"'))
     starlevels(\sym{*} 0.05 \sym{**} 0.01 \sym{***} 0.001, label(" \(p<@\)"))
     varwidth(12)
     modelwidth(12)
     delimiter(&)
     end(\\)
     prehead(`"{"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' `"\begin{tabular}{l*{4}{c}}"' `"\hline\hline"')
     posthead("\hline")
     prefoot("\hline")
     postfoot(`"\hline\hline"' `"\end{tabular}"' `"}"')
     mlabels(, depvar span prefix(\multicolumn{@span}{c}{) suffix(}))
     numbers(\multicolumn{@span}{c}{( )})
     eqlabels(, begin("\hline" "") nofirst)
     substitute(_ \_ "\_cons " \_cons)
     interaction(" $\times$ ")
     level(95)
     style(esttab)
    You could also add only the revised -esttab, prehead()- option to the -esttab- command, which will override the automatically-generated -estout, prehead()- option. As the manual warns, the prehead option "should be used with care" when used directly with -esttab-.

    Comment


    • #3
      Thanks!

      Comment

      Working...
      X