Hi everyone,
I am cleaning survey data from the Asianbarometer and want to standardize some variables to range from 0-1.
This is the code I usually use, in this case for the variable executive approval, that ranges from 1-4. I want it to range from 0-1. The variable educ ranges from 1-9. I also want it to range from 0 to 1.
Here is the data:
for some reason the code neither works for educ nor execapproval, something seems to be up with the labels but i cannot figure out what it is. It works if I create a new variable, for example:
But not for educ.
Can someone help?
Thank you so much!!
Best,
Hannah
I am cleaning survey data from the Asianbarometer and want to standardize some variables to range from 0-1.
This is the code I usually use, in this case for the variable executive approval, that ranges from 1-4. I want it to range from 0-1. The variable educ ranges from 1-9. I also want it to range from 0 to 1.
sum execapproval
replace execapproval = (execapproval - `r(min)') / (`r(max)'-`r(min)')
replace execapproval = (execapproval - `r(min)') / (`r(max)'-`r(min)')
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(educ execapproval) 7 2 8 3 5 3 8 2 7 3 7 3 5 3 3 1 9 . 8 1 7 3 6 2 6 3 5 2 6 2 7 1 4 2 7 2 8 3 5 3 7 3 1 . 1 3 3 4 1 . 8 3 end label values educ labels10 label def labels10 1 "No formal", modify label def labels10 3 "Complete primary /elementary", modify label def labels10 4 "Incomplete secondary/high", modify label def labels10 5 "Complete secondary/high", modify label def labels10 6 "Incomplete secondary/high school", modify label def labels10 7 "Complete secondary/high school", modify label def labels10 8 "Some university/college-level, with diploma", modify label def labels10 9 "With University/College degree", modify label values execapproval labels56 label def labels56 1 "Not at all satisfied", modify label def labels56 2 "Not very satisfied", modify label def labels56 3 "Fairly satisfied", modify label def labels56 4 "Very satisfied", modify
for some reason the code neither works for educ nor execapproval, something seems to be up with the labels but i cannot figure out what it is. It works if I create a new variable, for example:
gen educn = educ
sum educn
replace educn = (educn - `r(min)') / (`r(max)'-`r(min)')
label var educn "Education - normalized"
sum educn
replace educn = (educn - `r(min)') / (`r(max)'-`r(min)')
label var educn "Education - normalized"
Can someone help?
Thank you so much!!
Best,
Hannah
Comment