Docsity

Stata Commands for Chi-square Analysis: An Example with 'tabi' and 'drinks' Data, Study notes of Statistics

Toggle sidebar
bg1
Stata Commands for Module 9
Chi-square in Stata
For this example, we use “tabi” command, one of the so-called “immediate” commands
in Stata. The “immediate” commands apparently allow you to conduct analyses without
having an underlying dataset. According to Stata Help, “tabi displays the r x c table
using the values specified; rows are separated by '\'.” By putting “, chi2” at the end, you
are requesting that Stata include a chi-square statistic. (You can also just type “chi”.)
. tabi 776 401 307 \ 3306 1456 1053 \ 1667 927 789, chi2
| col
row | 1 2 3 | Total
-----------+---------------------------------+----------
1 | 776 401 307 | 1,484
2 | 3,306 1,456 1,053 | 5,815
3 | 1,667 927 789 | 3,383
-----------+---------------------------------+----------
Total | 5,749 2,784 2,149 | 10,682
Pearson chi2(4) = 57.9348 Pr = 0.000
Another example in Stata: Drinking by Religious Denomination
. * in Stata
. use "D:\soci708\data\survey2b.dta", clear
. tab drinks ...
. label define noyes 0 "No" 1 "Yes"
. label values drinks noyes
. tab drinks
DRINKS | Freq. Percent Cum.
------------+-----------------------------------
No | 52 20.31 20.31
Yes | 204 79.69 100.00
------------+-----------------------------------
Total | 256 100.00
. tab religion
RELIGION | Freq. Percent Cum.
------------+-----------------------------------
1 | 133 51.95 51.95
2 | 46 17.97 69.92
3 | 23 8.98 78.91
4 | 52 20.31 99.22
docsity.com
pf2

Partial preview of the text

Download Stata Commands for Chi-square Analysis: An Example with 'tabi' and 'drinks' Data and more Study notes Statistics in PDF only on Docsity!

Stata Commands for Module 9

Chi-square in Stata

For this example, we use “tabi” command, one of the so-called “immediate” commands

in Stata. The “immediate” commands apparently allow you to conduct analyses without

having an underlying dataset. According to Stata Help, “tabi displays the r x c table

using the values specified; rows are separated by ''.” By putting “, chi2” at the end, you

are requesting that Stata include a chi-square statistic. (You can also just type “chi”.)

. tabi 776 401 307 \ 3306 1456 1053 \ 1667 927 789, chi

| col

row | 1 2 3 | Total

Total | 5,749 2,784 2,149 | 10,

Pearson chi2(4) = 57.9348 Pr = 0.

Another example in Stata: Drinking by Religious Denomination

. * in Stata . use "D:\soci708\data\survey2b.dta", clear . tab drinks ... . label define noyes 0 "No" 1 "Yes" . label values drinks noyes . tab drinks DRINKS | Freq. Percent Cum. ------------+----------------------------------- No | 52 20.31 20. Yes | 204 79.69 100. ------------+----------------------------------- Total | 256 100. . tab religion RELIGION | Freq. Percent Cum. ------------+----------------------------------- 1 | 133 51.95 51. 2 | 46 17.97 69. 3 | 23 8.98 78. 4 | 52 20.31 99.

docsity.com

Total | 256 100.

. * set missing to two odd answers . replace religion=. if religion== (2 real changes made, 2 to missing) . label define denom 1 "Prot" 2 "Cath" 3 "Jewi" 4 "None" . label values religion denom . tab religion drinks | DRINKS RELIGION | No Yes | Total -----------+----------------------+---------- Prot | 39 94 | 133 Cath | 6 40 | 46 Jewi | 2 21 | 23 None | 5 47 | 52 -----------+----------------------+---------- Total | 52 202 | 254 . tab religion drinks, row nofreq V chi2 lr | DRINKS RELIGION | No Yes | Total -----------+----------------------+---------- Prot | 29.32 70.68 | 100. Cath | 13.04 86.96 | 100. Jewi | 8.70 91.30 | 100. None | 9.62 90.38 | 100. -----------+----------------------+---------- Total | 20.47 79.53 | 100. Pearson chi2(3) = 13.6827 Pr = 0. likelihood-ratio chi2(3) = 14.4258 Pr = 0. Cramér's V = 0. .

docsity.com