I am using the Stata command esttab to convert some tabulated output to Latex form. I want to include total number of observations in each column in the last row of the table. I have run across an issue using the keep suboption for blist. Sometimes keep performs as expected. Sometimes it does nothing.
I found the following on statalist, which suggests to me it may have something to do with the difference between coeflist and varlist, but I don't think that is the issue here. http://www.statalist.org/forums/forum/general-stata-discussion/general/131816-using-factor-variables-in-estimates-table-keep
Here is a reproducible example.
clear all
sysuse auto
gen big=(weight>3000)
label define Big 0 "Not in Big Set" 1 "In Big Set"
label values big Big
label variable big "Is Item Found in Big Set?"
compress big //want it to be byte to match my real data
estpost tabulate big foreign
esttab using myfilename.tex, replace f ///
cell(colpct(fmt(2)) b(fmt(g) par keep(Total))) ///
collabels(none) unstack noobs nonumber nomtitle ///
eqlabels(, lhs("Size Category")) ///
varlabels(, blist(Total "\hline "))
estpost tabulate rep78 foreign
esttab using myfilename2.tex, replace f ///
cell(colpct(fmt(2)) b(fmt(g) par keep(Total))) ///
collabels(none) unstack noobs nonumber nomtitle ///
eqlabels(, lhs("Repair Rec.")) ///
varlabels(, blist(Total "\hline "))
The latex output looks like this in the first case:
Size Category& Domestic& Foreign& Total\\
\hline
Not in Big Set& 28.85& 90.91& 47.30\\
& (15)& (20)& (35)\\
In Big Set & 71.15& 9.09& 52.70\\
& (37)& (2)& (39)\\
\hline Total & 100.00& 100.00& 100.00\\
& (52)& (22)& (74)\\
It looks like this (correct) in the second case:
Repair Rec. & Domestic& Foreign& Total\\
\hline
1 & 4.17& 0.00& 2.90\\
2 & 16.67& 0.00& 11.59\\
3 & 56.25& 14.29& 43.48\\
4 & 18.75& 42.86& 26.09\\
5 & 4.17& 42.86& 15.94\\
\hline Total & 100.00& 100.00& 100.00\\
& (48)& (21)& (69)\\
I also thought it may have something to do with my storage type, but adding recast int big before the first estpost didn't fix it.
Why is keep only working in one if these cases? How can it be fixed?
Or is there another workaround to achieve my goal of number of observations in each column appearing in the last row (labeling them "Number of observations" would be a bonus)?
estout, I'll make this a comment: perhaps someone will see that there is no answer and will provide the definitive answer. Thanks to your excellent reproducible example, I was able to discover that, in the spirit of your attempt by recastingbigas anint, removing the value label onbigled to the first case now matching the second case. Good luck taking it from here! - user4690969keep. However, it leads to the issue that I now don't have reasonable row labels. I feel like this should be solvable with theeqlabelsoption, but I haven't figured it out yet. - Daniellevarlabels- Danielle