I'd appreciate any comments you have on this code: gencat.
The purpose is to generate dummies and categorical variables in one line of code, avoiding the missing issue with generate. Included is a dataset with sex and race; I introduced missing as either . or -99.
An error is given if the variable exists. Also can use prefix. For either dummies or cats, you can create individual dummies (so, male and female) and include a prefix if you want to avoid interference with an existing variable.
target chooses which value you want to be coded 1 in a 0/1 situation.
zero sets the dummy to 0/1 in cases where you have 1/2 or some such.
The purpose is to generate dummies and categorical variables in one line of code, avoiding the missing issue with generate. Included is a dataset with sex and race; I introduced missing as either . or -99.
An error is given if the variable exists. Also can use prefix. For either dummies or cats, you can create individual dummies (so, male and female) and include a prefix if you want to avoid interference with an existing variable.
target chooses which value you want to be coded 1 in a 0/1 situation.
zero sets the dummy to 0/1 in cases where you have 1/2 or some such.
Code:
clear all use gencat_data , clear ** Sex tab SEX , missing gencat female = SEX , values(1 male 2 female) zero target(female) dummies ** Race tab RACE , missing gencat racecat = RACE , values(1 white 2 black 3 hispanic 4 asian 5 other) dummies ** Race with prefix gencat racecat2 = RACE , values(1 white 2 black 3 hispanic 4 asian 5 other) dummies prefix(race)

Comment