latex - omitting summary statistics from -tabstat- by subgroup if they are missing values -
i writing code export summary statistics table in latex using tabstat, by()
, esttab
.
here have toy example replicates structure of data:
cls clear set more off use auto, clear // create 2 groups used in -by()- option gen rep2="first dataset" if rep78>=3 replace rep2="second dataset" if rep78<3 // recode "price" missing in first group replace price=. if rep2=="first dataset" // table eststo: estpost tabstat weight price mpg trunk, /// column(statistics) statistics(count mean median sd) by(rep2) nototal local sum_statistics "count(label(observations)) mean(label(mean) fmt(2)) p50(label(median)) sd(label(standard deviation) fmt(2))" esttab using "table1.tex", replace type /// title("summary statistics") /// cells("`sum_statistics'") /// noobs nonum booktabs
the output displays summary statistics 2 subtables, 1 each dataset (as defined rep2
). these 2 datasets don't have same variables: price
missing first dataset.
i entirely omit row of summary statistics of price
"first dataset" (leaving "second dataset"). because since variable price
missing "first dataset", summary statistics missing values. equivalent omit entire row of summary statistics in case "observations" equal 0 in specific by-group.
i looked documentation of tabstat
not quite sure how proceed. have use drop()
option of estout
?
many thanks, s
as mention, can use drop()
option:
clear set more off sysuse auto, clear // create 2 groups used in -by()- option gen rep2="first" if rep78>=3 replace rep2="second" if rep78<3 // recode "price" missing in first group replace price=. if rep2=="first dataset" // table eststo: estpost tabstat weight price mpg trunk, /// column(statistics) statistics(count mean median sd) by(rep2) nototal local sum_statistics "count(label(observations)) mean(label(mean) fmt(2)) p50(label(median)) sd(label(standard deviation) fmt(2))" esttab, replace type /// title("summary statistics") /// cells("`sum_statistics'") /// noobs nonum booktabs drop(first:price)
this involves using full name , not variable name.
notice took out blank space in values of grouping variable. seems troublesome when calling esttab
, leave explore.
Comments
Post a Comment