Create dummy variable

Dummy variables are often used in regression analysis. Such variables need to be numerical and take the values 0 and 1.

This example shows how to make the dummy variable mann (male). First, all values are set to 0. The commando replace then replaces the value 0 with 1 where the variable kjønn (gender) takes the value ‘1’.

create-dataset demografidata
import BEFOLKNING_KJOENN as kjønn

//Make a dummy variable for male derived from kjønn

generate mann = 0
replace mann = 1 if kjønn == '1'