Tabulating zero frequencies in Stata

I had an annoyingly simple Stata question this afternoon which I couldn’t find an answer to on any of the usual forums. However, thanks to twitter, Michael Holmes and Jean Adams ‏I’ve managed to solve it without having to resort to the complicated scripting I thought I was going to have to write.

A simplification of the problem is that I needed to count how many people were in each of the 5 year age categories of my dataset i.e.

Age group
in years (5-year age groups)
Count
0 to 4

2

5 to 9

0

10 to 14

1

15 to 19

0

20 to 24

4

25 to 29

2

30 to 34

0

35 to 39

1

40 to 44

3

45 to 49

0

50 to 54

1

55 to 59

6

60 to 64

0

65 to 69

7

70 to 74

6

75 to 79

1

80 to 84

1

85 to 89

4

90 and over

7

 

Normally, I would just tabulate this data in STATA using

tab agegrp

However, when I actually run this on my dataset I get the equivelant of the following output

Age group
in years (5-year age groups)
Count
0 to 4

2

10 to 14

1

20 to 24

4

25 to 29

2

35 to 39

1

40 to 44

3

50 to 54

1

55 to 59

6

65 to 69

7

70 to 74

6

75 to 79

1

80 to 84

1

85 to 89

4

90 and over

7

 

Stata drops all the groups with a frequency of zero. These aren’t missing values (which could be fixed by adding the option missing to the end of the command above) they are actual zero frequencies.

Jean Adams kindly sent me a link to tabcount, which I’d come across previously, but I’m working on a site where this Stata module wasn’t installed. However, Michael then pointed out that I could execute it by copying and pasting the command into a text file, saving it with an ado extension and then running it from within Stata.

I’d never done this before, but it worked a treat, and I can now get the output I want by running:

tabcount agegrp, v(1/19)

v(1/19) just specifies which categories of agegrp I want the zero cells to be shown for (all of them in this case)

I’m putting this online as I found quite a few threads with people trying to find a similar solution so hopefully this might help someone else at some point. Thanks again to Jean and Michael.

Leave a Reply

Your email address will not be published. Required fields are marked *