Many thanks, Andrew.
I've tried to run your code but there is a error message.
I've tried to run your code but there is a error message.
Code:
. sysuse auto, clear (1978 Automobile Data) . local byvar rep78 . gen Mean= price . drop if missing(`byvar') (5 observations deleted) . expand 2, g(new) (69 observations created) . qui sum `byvar' . assert `byvar'!=99999 . replace `byvar'= 99999 if new variable rep78 was int now long (69 real changes made) . bys `byvar': egen Std_Err=sd(Mean) . bys `byvar': egen Freq=count(Mean) . collapse Mean Std_Err Freq, by("`byvar'") . estpost tabstat Mean Std_Err Freq, by("`byvar'") Summary statistics: mean for variables: Mean Std_Err Freq by categories of: rep78 rep78 | e(Mean) e(Std_E~) e(Freq) -------------+--------------------------------- 1 | 4564.5 522.5519 2 2 | 5967.625 3579.357 8 3 | 6429.233 3525.14 30 4 | 6071.5 1709.608 18 5 | 5913 2615.763 11 99999 | 6146.043 2912.44 69 -------------+--------------------------------- Total | 5848.65 2477.477 23 . esttab, cells("Mean Std_Err Freq") noobs nomtitle nonumber /// > collab(,lhs("`:var lab `byvar''")) drop(Total) /// > substitute("99999" "Total" "Std_Err" "Std. Err") varwidth(20) coefficient Total not found r(111); end of do-file r(111); .
Code:
CODE] sysuse auto, clear local byvar rep78 gen Mean= price drop if missing(`byvar') expand 2, g(new) qui sum `byvar' assert `byvar'!=99999 replace `byvar'= 99999 if new bys `byvar': egen Std_Err=sd(Mean) bys `byvar': egen Freq=count(Mean) collapse Mean Std_Err Freq, by("`byvar'") estpost tabstat Mean Std_Err Freq, by("`byvar'") esttab, cells("Mean Std_Err Freq") noobs nomtitle nonumber /// collab(,lhs("`:var lab `byvar''")) drop(Total) /// substitute("99999" "Total" "Std_Err" "Std. Err") varwidth(20) *LaTeX Table esttab, cells("Mean Std_Err Freq") noobs nomtitle nonumber /// collab(,lhs("`:var lab `byvar''")) drop(Total) /// substitute("99999" "Total" "Std_Err" "Std. Err") varwidth(20) tex
Comment