Use commandos `destring` and `recode` to make dummy variables
There is more than one way to make dummy variables (values 1 and 0). Perhaps the most basic way is by using the commandos
replace (see one of the other examples).
An alternative way of making dummy variables is by using the commandos
recode as illustrated in the example below.
sex takes the values ‘1’ and ‘2’ representing the values “Male” and “Female” respectively. The result of the procedure is a variable containing the values 1 and 0 representing male and female (=not male) respectively.
recode only accepts numerical valueformats, one must first convert from alfanumerical through the commando
destring. However, this is not necessary if the variable is numerical to begin with.
//Connect to databank require no.ssb.fdb:1 as fdb1 create-dataset demografidata import fdb1/BEFOLKNING_KJOENN as sex destring sex tabulate sex, nolabels recode sex (2 = 0) rename sex male //Check whether the recoding has been successful tabulate male, nolabels