0
votes

I am trying to get rid of a line with the statistics label/name "mean" in the output of the Stata code:

**********************************************************
**** Produce table with mean values of hhi_r, jsi_r, top4_r, hhi, jsi in 
decending order of hhi_r 

** sort output by mean hhi_r
drop mean group
egen mean = mean(hhi_r), by(name)
egen group = group(mean name)
replace group = -group 
labmask group, values(name) 
label var group "`: var label name'" 
** done sorting

label var hhi_r "rank(\$HHI\$)"
label var jsi_r "rank(\$C1_I\$)"
label var top4_r "rank(\$T4\$)"
label var hhi "\$HHI\$"
label var jsi "\$C1_I\$"

eststo clear
eststo t1: estpost tabstat jsi_r, by(group) statistics(mean) columns(statistics) listwise nototal
eststo t2: estpost tabstat top4_r, by(group) statistics(mean) columns(statistics) listwise nototal
eststo t3: estpost tabstat hhi, by(group) statistics(mean) columns(statistics) listwise nototal
eststo t4: estpost tabstat jsi, by(group) statistics(mean) columns(statistics) listwise nototal

eststo t0: estpost tabstat hhi_r, by(group) statistics(count mean sd p10 p25 p50 p75 p90) columns(statistics) listwise nototal

esttab t0 t1 t2 t3 t4 using "$Tables/hhi_r.tex", replace style(tex) type /// 
cells("mean(fmt(%15.0fc))") alignment(r) substitute(\_ _)  ///
noobs  nonumber varlabels(`e(labels)') varwidth(20) mlabels("rank(HHI)" "rank(C1)" "rank(T4)" "HHI" "C1")

The output is a TeX file that includes as the second line the label/name "mean" of the statistics:

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{5}{r}}
\hline\hline
                    &   rank(HHI)&    rank(C1)&    rank(T4)&         HHI&          C1\\
                    &        mean&        mean&        mean&        mean&        mean\\
\hline
624: Social Assistance&       2,332&           4&           4&      10,000&           1\\
425: Wholesale Electronic Markets and Agents and Broker&       2,332&            &            &      10,000&            \\
113: Forestry and Logging&       2,332&            &            &      10,000&            \\
115: Support Activities for Agriculture and Forestry&       2,326&            &            &       9,477&            \\
314: Textile Product Mills&       2,324&            &            &       7,501&            \\
112: Animal Production and Aquaculture&       2,321&            &            &       6,968&            \\
492: Couriers and Messengers&       2,318&       1,225&            &       6,821&         484\\
811: Repair and Maintenance&       2,316&           2&           2&       5,976&           1\\
\hline\hline
\end{tabular}
}

How can I suppress this line or replace the names/labels with the strings in the mlabels() option of the community-contributed command esttab?

1

1 Answers

1
votes

Using Stata's toy auto dataset as an example, the following works for me:

sysuse auto, clear      
eststo clear

eststo t1: estpost tabstat price, by(foreign) statistics(mean) columns(statistics) listwise nototal
eststo t2: estpost tabstat mpg, by(foreign) statistics(mean) columns(statistics) listwise nototal
eststo t3: estpost tabstat weight, by(foreign) statistics(mean) columns(statistics) listwise nototal
eststo t4: estpost tabstat length, by(foreign) statistics(mean) columns(statistics) listwise nototal

eststo t0: estpost tabstat mpg, by(foreign) statistics(count mean sd p10 p25 p50 p75 p90) columns(statistics) listwise nototal

esttab t0 t1 t2 t3 t4 using "table.tex", replace style(tex) ///
type cells(`"mean(fmt(%15.0fc) label(" "))"') alignment(r) substitute(\_ _)  ///
noobs  nonumber varlabels(`e(labels)') varwidth(20) ///
mlabels("rank(HHI)" "rank(C1)" "rank(T4)" "HHI" "C1")

type table.tex

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{5}{r}}
\hline\hline
                    &   rank(HHI)&    rank(C1)&    rank(T4)&         HHI&          C1\\
                    &            &            &            &            &            \\
\hline
Domestic            &          20&       6,072&          20&       3,317&         196\\
Foreign             &          25&       6,385&          25&       2,316&         169\\
\hline\hline
\end{tabular}
}

You basically substitute each statistic name with a space by specifying the label(" ") suboption in cells(mean()).

Alternatively, to eliminate the line completely use the option collabels(none):

esttab t0 t1 t2 t3 t4 using "table.tex", replace style(tex)  ///
type cells(`"mean(fmt(%15.0fc))"') alignment(r) substitute(\_ _)  ///
noobs  nonumber varlabels(`e(labels)') varwidth(20) ///
mlabels("rank(HHI)" "rank(C1)" "rank(T4)" "HHI" "C1") collabels(none)

type table.tex

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{5}{r}}
\hline\hline
                    &   rank(HHI)&    rank(C1)&    rank(T4)&         HHI&          C1\\
\hline
Domestic            &          20&       6,072&          20&       3,317&         196\\
Foreign             &          25&       6,385&          25&       2,316&         169\\
\hline\hline
\end{tabular}
}