EXERCISE 5 - ANSWER

How would you create a new variable that is equal to 1 for Africans and 0 for non-Africans?

The first step in creating the new variable is to determine which value of the variable race identifies Africans. From the SALDRU survey we know that the value 1 identifies an African respondent. With this knowledge, we are able to create the new variable.

generate newvar = 0
replace newvar = 1 if race == 1

The first command above creates a new variable called newvar that is equal to zero for every observation in the data. The second command line replaces the existing value of the variable newvar if the variable race is equal to 1, thus creating the desired variable.

 

BACK TO EXERCISE QUESTIONS