I'm confused about how table handles the "across" option in percent across rows. The simplest example I can show is using the auto.dta data where the "across" percentages differ from the direct calculation from the frequencies. At first I thought this might be due to some case/listwise deletion, but with no missing data in the auto data, I'm perplexed as to why I get differing numbers from the two approaches.
--------------------------------------------
| Car origin
| Domestic Foreign Total
--------------+-----------------------------
Mileage (mpg) |
12 | 100.00 100.00
14 | 85.55 14.45 100.00
15 | 100.00 100.00
16 | 100.00 100.00
17 | 54.16 45.84 100.00
18 | 83.02 16.98 100.00
19 | 100.00 100.00
20 | 100.00 100.00
21 | 69.27 30.73 100.00
22 | 100.00 100.00
23 | 100.00 100.00
24 | 78.18 21.82 100.00
25 | 19.98 80.02 100.00
26 | 72.19 27.81 100.00
28 | 74.19 25.81 100.00
29 | 100.00 100.00
30 | 51.71 48.29 100.00
31 | 100.00 100.00
34 | 100.00 100.00
35 | 100.00 100.00
41 | 100.00 100.00
Total | 77.20 22.80 100.00
--------------------------------------------
-------------------------------------------
| Car origin
| Domestic Foreign Total
--------------+----------------------------
Mileage (mpg) |
12 | 2 0 2
14 | 5 1 6
15 | 2 0 2
16 | 4 0 4
17 | 2 2 4
18 | 7 2 9
19 | 8 0 8
20 | 3 0 3
21 | 3 2 5
22 | 5 0 5
23 | 0 3 3
24 | 3 1 4
25 | 1 4 5
26 | 2 1 3
28 | 2 1 3
29 | 1 0 1
30 | 1 1 2
31 | 0 1 1
34 | 1 0 1
35 | 0 2 2
41 | 0 1 1
Total | 52 22 74
-------------------------------------------
For example, for mileage level 17, there are 2 foreign and 2 domestic, so I would expect the "across" table to generate 50% for each, but using percent I get 54.16 and 45.84. Is there an option that I'm missing? I feel like it must be something simple, but the difference between the percent option and doing the raw division is flummoxing me.
Code:
. sysuse auto, clear (1978 automobile data) . table mpg foreign, stat(percent weight, across(foreign)) zerocounts
--------------------------------------------
| Car origin
| Domestic Foreign Total
--------------+-----------------------------
Mileage (mpg) |
12 | 100.00 100.00
14 | 85.55 14.45 100.00
15 | 100.00 100.00
16 | 100.00 100.00
17 | 54.16 45.84 100.00
18 | 83.02 16.98 100.00
19 | 100.00 100.00
20 | 100.00 100.00
21 | 69.27 30.73 100.00
22 | 100.00 100.00
23 | 100.00 100.00
24 | 78.18 21.82 100.00
25 | 19.98 80.02 100.00
26 | 72.19 27.81 100.00
28 | 74.19 25.81 100.00
29 | 100.00 100.00
30 | 51.71 48.29 100.00
31 | 100.00 100.00
34 | 100.00 100.00
35 | 100.00 100.00
41 | 100.00 100.00
Total | 77.20 22.80 100.00
--------------------------------------------
Code:
. table mpg foreign, stat(count weight) zerocounts
-------------------------------------------
| Car origin
| Domestic Foreign Total
--------------+----------------------------
Mileage (mpg) |
12 | 2 0 2
14 | 5 1 6
15 | 2 0 2
16 | 4 0 4
17 | 2 2 4
18 | 7 2 9
19 | 8 0 8
20 | 3 0 3
21 | 3 2 5
22 | 5 0 5
23 | 0 3 3
24 | 3 1 4
25 | 1 4 5
26 | 2 1 3
28 | 2 1 3
29 | 1 0 1
30 | 1 1 2
31 | 0 1 1
34 | 1 0 1
35 | 0 2 2
41 | 0 1 1
Total | 52 22 74
-------------------------------------------
Comment