Syntax for chi-square test in SPSS

In some situations, the syntax is easier than the visual menu to use in SPSS. This tutorial provides examples of syntax for chi-square test in SPSS.

2 Examples of Syntax for chi-square test in SPSS

Example 1: One variable

The first example is the one variable chi-square test. The following is example data for one variable, with 3 groups.

Course NamesStudent Counts
Math25
Computer50
English30
Data of one variable
DATA LIST LIST / a count.
BEGIN DATA.
1 25
2 50
3 30
END DATA.
WEIGHT BY count.
NPAR TESTS
/CHISQUARE=a.

Example 2: two variables

We can also do two variable chi-square tests using SPSS syntax. The following is an example of data of two variables.

Course NamesGenderStudent Counts
MathFemale15
MathMale10
ComputerFemale25
ComputerMale25
EnglishFemale17
EnglishMale13
Data of two variables

The following is the SPSS syntax.

DATA LIST LIST / Course Gender count.
BEGIN DATA
1 1 15
1 2 10
2 1 25
2 2 25
3 1 17
3 2 13
END DATA.
WEIGHT BY count.
CROSSTABS Course BY Gender
/STATISTIC=CHISQ.

Reference:

Further Reading: