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.
Related Posts with generating many dummy variables with the var name and label name
Error naming output files from macroHello, looping over a series of input files, I want to create a series of output files and name the…
Dropping duplicated pairs of two variablesI have a dataset which contains three variables: CityA, CityB and Dstance. See the following example…
Error naming output files from macroHello, looping over a series of input files, I want to create a series of output files and name the…
Questions about teffects nnmatch & error use option osample()Dear Stata Community! I hope you can help me out with some of the questions I have regarding the ne…
Delete panel observations which are nonconsecutive dataI have monthly time-series data for 4435-panel ids. Time series should be for consecutive months. Ho…
Subscribe to:
Post Comments (Atom)
0 Response to generating many dummy variables with the var name and label name
Post a Comment