I am trying to use esttab to create a LaTeX table with summary statistics using the summarize command. I can use code like the following to do this if I summarize multiple variables at once:
sysuse auto, clear
global vars price mpg headroom
eststo clear
eststo: estpost sum $vars, listwise
esttab est*, cells("count mean(fmt(2)) sd") nomtitles nonumber noobs
However, I am not sure how to summarize one line, store it, summarize another, store it, etc., and then combine all of them in the same table without creating unnecessary columns. I may want to summarize each variable individually if I want to make individualized restrictions by variable on which observations to summarize.
Here is code that doesn't get me what I want. Specifically, it does not put the summary statistics for each variable under the same column, but instead creates new columns, each set of which correspond to a different variable.
eststo clear
gen count = 1
foreach i in $vars {
eststo: estpost sum `i' if `i'>count
replace count = count+1
}
esttab est*, cells("count mean(fmt(2)) sd") nomtitles nonumber noobs
What should I change to get me my desired result?