# RE: st: RE: tab

 From David Kantor To statalist@hsphsun2.harvard.edu Subject RE: st: RE: tab Date Thu, 11 Dec 2003 12:50:10 -0500

-,subpop()- is like an -if-, or an additional -if- if there already is one; it limits the set of observations that are tabulated. But the set of values appearing in the table are not limited by the subpop variable, and so, some cells can have zeroes. (When applied to two-way tabulations, whole rows or columns might have all zeroes.)

I don't think you can successfully combine -,subpop()- with -bysort-, because the limiting subpopulation would need to be different for each value of the by-variable.

But you can do a separate -tab ..., subpop()- for each value of the categorical variable that you would normally think of as your bysort variable. If this is done to one-way tabulations, then each instance is just like a column (or row) of a two-way tabulation, complete with cells having zeroes.

Thus, with the auto data, if all you want is the table for where foreign ==1, you can do...

tab rep78, subpop(foreign)

(This takes a shortcut, using the fact that foreign is coded 0 and 1. More generally, you would do something such as...
gen byte foreign1 = foreign==1 // or "Foreign":origin
tab rep78, subpop(foreign1)

... and similarly for any other value corresponding to a desired limiting population.)

But in this case, if you were to do...
gen byte foreign0 = foreign==0 // or "Domestic":origin
tab rep78, subpop(foreign0)
you would get the same result as...
tab rep78 if foreign==0
because there are no rep78 values beyond those seen within the set where foreign==0.

My comment about extending the dataset applies only if there are values of the tabulated variable that exist nowhere in the dataset.

I hope this is useful (and correct).
-- David

At 04:01 PM 12/11/2003 +0000, you wrote:

```Thanks for the reference to -, subpop()- which
somehow has never registered with me; indeed
I don't think I ever understood it.

Here is the sort of example I had in mind. Some
people would like explicit zeros in the case
of rep78 == 1, 2 & foreign == 1. Can -, subpop()-
help here, directly, without changing the dataset?

(This was one motivation for writing -tabcount-,
now on SSC. I thought that such tables should be
possible on the fly, so far as the user is
concerned.)

. bysort foreign : tab rep78
[...]
```
```David Kantor
Institute for Policy Studies
Johns Hopkins University
dkantor@jhu.edu
410-516-5404

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```