Hi Stata users,
I would like to generate a new variable based on the contents of a value label. Below is an example am trying to come up with so that I can replicate in my dataset
The idea is to create a new variable if a string is part of a value label.
Thanks in advance!
I would like to generate a new variable based on the contents of a value label. Below is an example am trying to come up with so that I can replicate in my dataset
Code:
sysuse auto, clear
gen dum = .
levelsof foreign, local(levels)
foreach l of local levels {
di "`: label (foreign) `l''"
replace dum = 0 if inlist("`: label (foreign) `l''", "Domestic")
replace dum = 1 if inlist("`: label (foreign) `l''", "Foreign")
}
Thanks in advance!

Comment