SO5032: Lab Materials

Table of Contents

1. Week 5 Lab

1.1. Interaction effects

Interaction is where the effect of one variable depends on the level of another. For instance, in predicting income, both age and education may have direct effects, but the effect of education may be less for older people (due to the time elapsed since leaving education). That is, an additional year of education may boost income more for young people than for older people. We can accommodate this by adding an extra variable to the model, consisting of age multiplied by education. If this is significant, it tells us how the effect of education changes for each year of age.

1.1.1. Interaction between binary and continuous variables

The BHPS data that we have already looked at, on hours, income and gender, allow us to look at an interaction between gender and hours in predicting income. Load the data:

library(foreign)
oind <- read.dta("https://teaching.sociology.ul.ie/so5032/oind.dta")
names(oind)

Then execute the following syntax:

oind$intvar <- oind$Hours * (oind$Gender=="female")
summary(lm(data=oind, Income ~ Hours + Gender))
summary(lm(data=subset(oind, Gender=="male"), Income ~ Hours))
summary(lm(data=subset(oind, Gender=="female"), Income ~ Hours))
summary(lm(data=oind, Income ~ Hours + Gender + intvar))

Draw the regression lines for the second and third models.

Then do so for the fourth, and compare the findings from those models.

1.1.2. Formula syntax

Note that while creating a new variable by multiplying the two X-variables works, formula syntax makes this easier:

summary(lm(data=oind, Income ~ Hours*Gender))

1.1.3. NLSW88 data

Load the NLSW88 data:

nlsw88 <- read.dta("https://teaching.sociology.ul.ie/so4046/nlsw88.dta")

Fit a model predicting wage by hours and union-membership, and interpret. Add an interaction between hours and union: what does it do?

1.2. Interaction between two continuous variables

With the oind data, fit a regression predicting income using hours and job-score. Add an interaction and interpret it.

For the models without and with the interaction, draw graphs relating hours (Hours) to income (Income) for job score at 20 and 80.

For both models, calculate the effect of a 1-unit increase in hours on income, for job score at 20 and 80.

Author: Brendan Halpin

Created: 2026-02-24 Tue 13:53

Validate