Howdy!
I've been tasked with cleaning and recoding a dataset.
I've come across two sets of measures with 84 items. All items are stored as a strings and I am converting them to numeric for analysis.
My current code looks like this, and I will be adapting this structure code for ccnes1 to ccnes84.:
*CCNES1*
replace ccnes1 = "." if ccnes1 == ""
replace ccnes1 = "1" if ccnes1 == "(Very unlikely)1"
replace ccnes1 = "2" if ccnes1 == "2"
replace ccnes1 = "3" if ccnes1 == "3"
replace ccnes1 = "4" if ccnes1 == "(Neither likely nor unlikely)4"
replace ccnes1 = "5" if ccnes1 == "5"
replace ccnes1 = "6" if ccnes1 == "6"
replace ccnes1 = "7" if ccnes1 == "(Very likely)7"
*Converting from string to numeric
destring ccnes1, gen(ccnes1_n)
*Dropping old variable
drop ccnes1
*Renaming new variablepbace8
rename ccnes1_n ccnes1
*Labelling new variable
lab def ccnes 1 "(Very unlikely) 1" 2 "2" 3 "3" 4 "(Neither likely nor unlikely) 4" 5 "5" 6 "6" 7 "(Very likely) 7"
lab val ccnes1 ccnes
*Checking variable
codebook ccnes1
Is there a more efficient way to recode, and relabel, rather than using the above code 84 different times for the individual questions in the measure?
Thanks in advance hivemind!
I've been tasked with cleaning and recoding a dataset.
I've come across two sets of measures with 84 items. All items are stored as a strings and I am converting them to numeric for analysis.
My current code looks like this, and I will be adapting this structure code for ccnes1 to ccnes84.:
*CCNES1*
replace ccnes1 = "." if ccnes1 == ""
replace ccnes1 = "1" if ccnes1 == "(Very unlikely)1"
replace ccnes1 = "2" if ccnes1 == "2"
replace ccnes1 = "3" if ccnes1 == "3"
replace ccnes1 = "4" if ccnes1 == "(Neither likely nor unlikely)4"
replace ccnes1 = "5" if ccnes1 == "5"
replace ccnes1 = "6" if ccnes1 == "6"
replace ccnes1 = "7" if ccnes1 == "(Very likely)7"
*Converting from string to numeric
destring ccnes1, gen(ccnes1_n)
*Dropping old variable
drop ccnes1
*Renaming new variablepbace8
rename ccnes1_n ccnes1
*Labelling new variable
lab def ccnes 1 "(Very unlikely) 1" 2 "2" 3 "3" 4 "(Neither likely nor unlikely) 4" 5 "5" 6 "6" 7 "(Very likely) 7"
lab val ccnes1 ccnes
*Checking variable
codebook ccnes1
Is there a more efficient way to recode, and relabel, rather than using the above code 84 different times for the individual questions in the measure?
Thanks in advance hivemind!

Comment