# 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:

use http://teaching.sociology.ul.ie/so5032/labs/ojbhrs

Then execute the following syntax:

gen female = osex==2 gen inter = female*ojbhrs reg ofimn female reg ofimn female ojbhrs reg ofimn female ojbhrs inter

Draw the regression lines for the second and third models. Fit bi-variate models for men and women separately (i.e. only ojbhrs as the explanatory variable) and compare the findings from those models.

#### 1.1.2. Stata formula syntax

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

reg ofimn i.osex##c.ojbhrs

This command gives the same results, treating `osex`

as a categorical variable (`i.`

) and ojbhrs as a continuous one (`c.`

).

### 1.2. Interaction between two continuous variables

We will use the Stata built-in NLSW88 data extract to explore
interaction between work-experience, `ttl_exp`

, and years of education,
`grade`

, in predicting wage.

sysuse nlsw88, clear

Fit a regression model without and then with an interaction effect.
For both models, draw graphs relating experience (`ttl_exp`

) to
wage (`wage`

) for education (`grade`

) at 10 and 15 years.

For both models, calculate the effect of a 1-unit increase in work experience on wage, for education at 5 and 20 years.