# Multiple interaction effect in logistic regression

In the following example there are multiple interaction terms in the regression. Here we are going to include an interaction term for the big city and for the education, because we would like to see if there is an interaction between these two variables.

**Research question:** How does the effect of residence/domicile changes in the categories of the different educations? So, how big is the effect between primary, secondary, and also tertiary educated people?

weight by pspwght.

fre pbldmn.

RECODE pbldmn (1=1)(2=0) into pbldmn_2cat.

VARIABLE LABELS pbldmn_2cat ‘taking part or not in lawful public demonstration last 12 months?’.

VALUE LABELS pbldmn_2cat 1’yes’ 0’no’.

fre pbldmn pbldmn_2cat.

fre gndr.

RECODE gndr (1=1)(2=0) into gndr_2cat.

VARIABLE LABELS gndr_2cat ‘gender=male’.

VALUE LABELS gndr_2cat 1’male’ 0’female’.

fre gndr gndr_2cat.

fre domicil.

RECODE domicil (1 2=1)(3 thru 5=0) into domicil_2cat.

VARIABLE LABELS domicil_2cat ‘domicil=big city’.

VALUE LABELS domicil_2cat 1’big city or outskirts’ 0’not big city’.

fre domicil domicil_2cat.

fre edulvlb.

RECODE edulvlb (0 thru 213=1)(313 thru 800=0) INTO

edulvlb_primary_dummy.

VARIABLE LABELS edulvlb_primary_dummy ‘Highest education level=primary’.

VALUE LABELS edulvlb_primary_dummy 1’Primary or below’ 0’Higher than primary’.

fre edulvlb edulvlb_primary_dummy.

fre edulvlb.

RECODE edulvlb (313 thru 520=1)(0 thru 213=0)(610 thru 800=0) INTO edulvlb_secondary_dummy.

VARIABLE LABELS edulvlb_secondary_dummy ‘Highest education level=secondary’.

VALUE LABELS edulvlb_secondary_dummy 1’Secondary’ 0’Not secondary’.

fre edulvlb edulvlb_secondary_dummy.

fre edulvlb.

RECODE edulvlb (0 thru 520=0)(610 thru 800=1) INTO edulvlb_tertiary_dummy.

VARIABLE LABELS edulvlb_tertiary_dummy ‘Highest education level=tertiary’.

VALUE LABELS edulvlb_tertiary_dummy 1’Tertiary’ 0’Not tertiary’.

fre edulvlb edulvlb_tertiary_dummy.

LOGISTIC REGRESSION pbldmn_2cat WITH gndr_2cat domicil_2cat edulvlb_secondary_dummy edulvlb_tertiary_dummy.

*===================================.

*INTERACTION EFFECT.

COMPUTE inter_domicil_secondary=domicil_2cat *

edulvlb_secondary_dummy.

COMPUTE inter_domicil_tertiary=domicil_2cat * edulvlb_tertiary_dummy.

LOGISTIC REGRESSION pbldmn_2cat WITH gndr_2cat domicil_2cat edulvlb_secondary_dummy edulvlb_tertiary_dummy inter_domicil_secondary inter_domicil_tertiary.

**We need (k-1)*(m-1) interaction terms.**

(The number of the categories of the first variable-1)*(The number of categories of the second variable-1)

(2-1)*(3-1)=2 -> so, we will need 2 interaction terms.

2: small city, big city

3: primary, seconday, tertiary

**So, we will have to create 2 interaction terms:**

big city*secondary education

big city*tertiary education

For primary education, we will not have to create interaction term because that is our reference category, that one we will just leave out of the regression.

So, we will see the interaction differently in secondary and in tertiary education groups.

**In conclusion,** we can say that there is no evidence for the presence of an interaction effect because the p values of the inter variables are higher than 0,05. So, the effect of domicile in these different categories of education seems to be similar.

## Example

When your independent variable has more than 2 categories, then you need more than one interaction terms.

weight by pspwght.

fre cgtsmke.

RECODE cgtsmke (1 2=1) (3 thru 5=0) INTO cgtsmke_dummy.

VARIABLE LABELS cgtsmke_dummy ‘Smoking? (1=yes)’.

VALUE LABELS cgtsmke_dummy 1’yes’ 0’no’.

fre cgtsmke cgtsmke_dummy.

fre gndr.

RECODE gndr (1=1)(2=0) into gndr_2cat.

VARIABLE LABELS gndr_2cat ‘gender=male’.

VALUE LABELS gndr_2cat 1’male’ 0’female’.

fre gndr gndr_2cat.

fre domicil.

RECODE domicil (1 2=1)(3 thru 5=0) into domicil_2cat.

VARIABLE LABELS domicil_2cat ‘domicil=big city’.

VALUE LABELS domicil_2cat 1’big city or outskirts’ 0’not big city’.

fre domicil domicil_2cat.

fre edulvlb.

RECODE edulvlb (0 thru 213=1)(313 thru 800=0) INTO

edulvlb_primary_dummy.

VARIABLE LABELS edulvlb_primary_dummy ‘Highest education level=primary’.

VALUE LABELS edulvlb_primary_dummy 1’Primary or below’ 0’Higher than primary’.

fre edulvlb edulvlb_primary_dummy.

fre edulvlb.

RECODE edulvlb (313 thru 520=1)(0 thru 213=0)(610 thru 800=0) INTO edulvlb_secondary_dummy.

VARIABLE LABELS edulvlb_secondary_dummy ‘Highest education level=secondary’.

VALUE LABELS edulvlb_secondary_dummy 1’Secondary’ 0’Not secondary’.

fre edulvlb edulvlb_secondary_dummy.

fre edulvlb.

RECODE edulvlb (0 thru 520=0)(610 thru 800=1) INTO edulvlb_tertiary_dummy.

VARIABLE LABELS edulvlb_tertiary_dummy ‘Highest education level=tertiary’.

VALUE LABELS edulvlb_tertiary_dummy 1’Tertiary’ 0’Not tertiary’.

fre edulvlb edulvlb_tertiary_dummy.

LOGISTIC REGRESSION pbldmn_2cat WITH gndr_2cat domicil_2cat edulvlb_secondary_dummy edulvlb_tertiary_dummy.

*===================================.

*INTERACTION EFFECT.

COMPUTE inter_domicil_secondary=domicil_2cat *

edulvlb_secondary_dummy.

COMPUTE inter_domicil_tertiary=domicil_2cat * edulvlb_tertiary_dummy.

LOGISTIC REGRESSION cgtsmke_dummy WITH gndr_2cat domicil_2cat edulvlb_secondary_dummy edulvlb_tertiary_dummy inter_domicil_secondary inter_domicil_tertiary.

**b1: **Gender has a significant effect on smoking (p=0,000), everything else held constant.

**b2:** The difference between big city residents and small city residents regarding smoking habits is -0,675, everything else held constant. So, the log odds of smoking among big city residents is lower by 0,675 than among small city residents, everything else held constant. Domicile has a negative significant effect on smoking (p=0,026), everything else held constant.

**b3:** We don’t have evidence that secondary educated people have different smoking habits from primary educated people, everything else held constant. (p=0,528)

**b4: **Tertiary educated people have different smoking habits from primary educated people, everything else held constant. (p=0,000) So, we have evidence that there is a difference between the tertiary and primary educated people in terms of smoking habits, everything else held constant. (p=0,000)

**b5 (inter_domicil_secondary):** This is not significant (p=0,076).

**b6 (inter_domicil_tertitary):** This is significant (p=0,016).

**b5 (inter_domicil_secondary)+b2** **(domicile):** The difference between small and big city residents among secondary educated people.

**b6 (inter_domicil_tertitary) + b2(domicile): ** (p=0,015) -1,085+(-0,675)=0,41 The log odds of smoking between big city residents and small city residents among tertiary-educated people is 0,41. So, the log odds of smoking among tertiary educated people in big cities are higher by 0,41 than among the same group but living in small cities. So, the effect of domicile among tertiary educated people is higher among big city residents than among small city residents. Note: this is only true for **tertiary educated people.**

So, here we compared the effect of big city in the three different groups of education.