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 male
. First, all values are set to 0. The replace
command then replaces the value 0 with 1 where the variable gender
takes the value ‘1’.
//Connect to datastore
require no.ssb.fdb:23 as db
create-dataset demography
import db/BEFOLKNING_KJOENN as gender
//Create a dummy variable that indicates males based on the variable gender
generate male = 0
replace male = 1 if gender == '1'
tabulate male