I have a gender column that says either "Female", "Male", or . for missing entry. I want to create a new column that gives dummy variable 1 if gender is female and 0 is gender is male (and continuing to give . for missing value). I tried to do gen Fem = gender = "Female" but this does not work and I get r(109) error.
I am assuming this is because the gender column is a byte format column.
Also, how do I interact dummy variable column with variables in a regression model on Stata?
1 Answer 1
See help fvvarlist, and check out the information on the binary operator #
For a specific example, see below where I create a 100 row dataset with variables y, x1, x2, and gender, the last of which should be similar to yours (i.e. byte with Male and Female labels)
clear
set obs 100
set seed 123
gen byte gender = runiform()<0.3
recode gender 0=1 1=2
label define gender 1 "Male" 2 "Female"
label values gender gender
gen x1 = runiform()<0.7
gen x2 = runiform()<0.2
gen y = runiform()<0.5
I can include a interaction term using the # operator
regress y x1 x2 x1#gender
1 Comment
regress y x2 x1##i.gender more legible and the code easier to scan.
gendervariable is already a dummy variable, but simply has value labels. (to see this comparetab genderwithtab gender, nolabel). You do not need to create a new variable.byteis a variable or storage type and not a (display) format.