Hi all!
I have a set of variables that contain both numeric and string values. I have converted all the variables into numeric only, but can't seen to get the codes right to classify the values into groups.
*making list
global mycomean afb1_mean afb2_mean afm1_mean afg1_mean afg2_mean ///
fb1_mean ota_mean cit_mean dhcit_mean don_mean donglca_mean zen_mean
describe $mycomean
*keping the original string vars of mean mycotoxin levels
foreach var of global mycomean {
gen o_`var' = `var'
}
*string to numeric
foreach var of global mycomean {
encode `var', generate(n_`var')
}
*replace values
foreach i of varlist n_zen_mean n_donglca_mean n_don_mean n_dhcit_mean ///
n_cit_mean n_ota_mean n_fb1_mean n_afg2_mean n_afg1_mean n_afm1_mean ///
n_afb2_mean n_afb1_mean {
replace `i' = 0 if `i' == .
replace `i' = 1 if `i' == >LOD
replace `i' = 2 if `i' = > 0
}
the >LOD part remains even after destringing the vars.
Can anyone have a look and tell me where I'm getting the code wrong?
I have a set of variables that contain both numeric and string values. I have converted all the variables into numeric only, but can't seen to get the codes right to classify the values into groups.
*making list
global mycomean afb1_mean afb2_mean afm1_mean afg1_mean afg2_mean ///
fb1_mean ota_mean cit_mean dhcit_mean don_mean donglca_mean zen_mean
describe $mycomean
*keping the original string vars of mean mycotoxin levels
foreach var of global mycomean {
gen o_`var' = `var'
}
*string to numeric
foreach var of global mycomean {
encode `var', generate(n_`var')
}
*replace values
foreach i of varlist n_zen_mean n_donglca_mean n_don_mean n_dhcit_mean ///
n_cit_mean n_ota_mean n_fb1_mean n_afg2_mean n_afg1_mean n_afm1_mean ///
n_afb2_mean n_afb1_mean {
replace `i' = 0 if `i' == .
replace `i' = 1 if `i' == >LOD
replace `i' = 2 if `i' = > 0
}
the >LOD part remains even after destringing the vars.
Can anyone have a look and tell me where I'm getting the code wrong?
Comment