我正在尝试消除Stata代码输出中带有统计标签/名称为“ mean”的行:
**********************************************************
**** 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")
输出是一个TeX文件,其中第二行包括统计信息的标签/名称“均值”:
{
\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}
}
如何隐藏此行或用 community-contributed 命令mlabels()
的{{1}}选项中的字符串替换名称/标签?
答案 0 :(得分:1)
以Stata的玩具auto
数据集为例,以下对我有用:
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}
}
您基本上可以通过在label(" ")
中指定cells(mean())
子选项来用空格替换每个统计名称。
或者,要完全消除该行,请使用选项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}
}