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
Dates from Excel/CSV not correctly displaying in StataI imported several csv files with "birthdate" as one of the variables into Stata and then I appended…
Why the number of observation decrease when I increase the sample size?Hi all, Today I face a strange situation that the number of observations shrinking when I expand th…
How to see the frequency of a veriables in each country in a dataset ?By the helps from others, I see that I can list the unique countries from a sample by using\ tab GE…
What is wrong with inlist2 in my code?Hi all, Yesterday, as documented from this post (https://www.statalist.org/forums/for...p-of-countr…
division of two-column using if functionHello, I have this dataset, and I want to divide CLMS18/CLMS17 if NPI17 is the same as NPI18 and the…
Subscribe to:
Post Comments (Atom)
0 Response to generating many dummy variables with the var name and label name
Post a Comment