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
How to flag an event of interest in a longitudinal datasetHi, I have a hospital admission data in which every patient may have one to hundreds of repeated ad…
Surpress "percent" label on "x"-axis of graph hbarDear Statalists, I coded a horizontal bar graph which looks exactly how I desire it. Only problem i…
Durbin-Wu-Hausman test for GEEsDear Stata Forum I am running a GEE panel regression. I would like to check for endogeneity using …
Calculate and visualize horizontal distance between 2 (time series) linesHello, Is there a convenient way to calculate and visualize horizontal distance between 2 lines? See…
Creating a dummy if value from other dataset is foundDear Statalist users, The past few days I have been trying to accomplish something, which I till no…
Subscribe to:
Post Comments (Atom)
0 Response to generating many dummy variables with the var name and label name
Post a Comment