Hi all,
Although I was going through some of the website links, I could not solve my issue. So, I am posting here and seeking the help. My issue is that I need to generate manynew dummy varaibles out of a categorical variable. For example the variable name is districtname_main which is a string type and it has 32 districts (See the attached picture). I have to gen all of them into new binary dummy variables with the var name and label name of that particular district. So I tried the following command but did not work.
foreach var of districtname_main {
gen dist_`var'=0
replace dist_`var'=1 if districtname_main ==real("`var'")
}
I also tried many other methods suggested on various websites. But nothing worked. I wonder if someone could help me out from this issue.
0 Response to generating many dummy variables with the var name and label name
Post a Comment