This is pretty easy:
/* Make some fake data */
sysuse auto, clear
gen make_only = subinstr(lower(word(make,1)),".","",.)
/* Create meaningful dummies */
levelsof make_only, clean local(makes)
foreach m of local makes {
gen `m' = cond(make_only=="`m'",1,0)
}
However, it is probably easier to just use factor variables notation:
sencode make_only, label(make_only) replace
reg price i.make_only
list make price if make_only=="amc":make_only
Regression output will be nicely labeled, you don't create extra variables, and it's easy enough to refer to particular values.
sencode
is written by Roger Newson and is available from SSC.