I am trying to create many tables of cross-tabs in the style of tab
(twoway) or tabout
in Stata. However, I want to include response options for both variables, even if every cell for that variable in the twoway tabulation would be zero. For instance, if we alter the auto dataset slightly:
sysuse auto
tab rep78 foreign
* Altering data
replace foreign=. if foreign==0 & rep78==1
tab rep78 foreign
In the altered data, it is possible that there could be a car with rep78==1
, but there are no instances of that in the data among observations that are non-missing for the variable foreign
.
What I want is a table like:
Repair
Record Car type
1978 Domestic Foreign Total
1 0 0 0
2 8 0 8
3 27 3 30
4 9 9 18
5 2 9 11
Total 46 21 67
Nick Cox's very nice tabcount
works for this purpose but
- I don't want to have to specify all the possible response options to include
and
- I want to be able to export the tables cleanly as in
tabout
. I often have to create batches of tables where a lot of cells in the tables will have zero observations due to missingness, and I often have many, many possible response options.
Any ideas on a workaround that will allow me to still use tabout
or something similar?