10.1 Variables that are not numbers

How do you put “urban” into an equation?

The wage data record where each worker lives.

wages <- read.csv("data/wages-india-synthetic.csv")
wages$lw <- log(wages$annual_earnings)

table(wages$residence)
#> 
#> Rural Urban 
#> 14631  5369

There is no arithmetic to do here. Urban minus rural is not a number, and no amount of care about units will make it one.

The difficulty is not peculiar to residence. A great deal of what economists want to compare arrives in exactly this form: male and female, treated and control, public and private school, manufacturing and services, before and after the introduction of GST. In every case the variable sorts observations into groups rather than placing them on a scale.

What we can do is record whether a condition holds.

A dummy variable — also called an indicator, or a binary variable — takes the value 1 when a condition is true and 0 when it is false.

\[\text{urban}_i = \begin{cases} 1 & \text{if worker } i \text{ lives in an urban area} \\ 0 & \text{otherwise} \end{cases}\]

It is a number, so a regression can use it. What makes it different from other numbers is that it takes only two values, so “a one-unit increase” means switching from one group to the other.

wages$urban <- as.integer(wages$residence == "Urban")
wages$male  <- as.integer(wages$sex == "Male")

head(data.frame(residence = wages$residence, urban = wages$urban))
#>   residence urban
#> 1     Rural     0
#> 2     Rural     0
#> 3     Urban     1
#> 4     Urban     1
#> 5     Rural     0
#> 6     Urban     1

The choice of which category gets the 1 is arbitrary. Coding rural as 1 instead would flip the sign of the coefficient and change nothing else.