Good afternoon all,
Please this is part of my dataset below
I have run encode with the following 2 codes
* Define a macro list of all variables with the same values
local sign_vars SignFever SignActivity SignBreathing SignFeeding SignVomiting SignStooling SignSeizures SignsOther SignsColor
foreach var of local sign_vars {
qui describe `var'
// Check if variable is string type
if "`r(typ)'" == "str" {
qui tab `var' if !missing(`var')
if r(N) > 0 {
encode `var', gen(`var'_encoded)
label define `var'_labels 1 "Spontaneous" ///
2 "Prompted" ///
3 "Not familiar with this sign"
label values `var'_encoded `var'_labels
drop `var'
rename `var'_encoded `var'
}
}
}
// Define a macro list of all variables to be encoded
local sign_vars SignFever SignActivity SignBreathing SignFeeding SignVomiting SignStooling SignSeizures SignsOther SignsColor
// Loop through each variable
foreach var of local sign_vars {
// Describe variable
qui describe `var'
// Check if variable is string type
if "`r(typ)'" == "str" {
// Tabulate non-missing values
qui tab `var' if !missing(`var')
// Check if there are non-missing values
if r(N) > 0 {
// Encode the variable
encode `var', gen(`var'_encoded)
// Define labels
label define `var'_labels 1 "Spontaneous" ///
2 "Prompted" ///
3 "Not familiar with this sign"
// Apply labels
label values `var'_encoded `var'_labels
// Drop original variable
drop `var'
// Rename encoded variable to original variable name
rename `var'_encoded `var'
}
}
}
At the end of each, and severally, it executes without any error messages but makes no changes to the dataset. They remain as string variables. What may be wrong please? I am using Stata 18
Obumneme Ezeanosike
Please this is part of my dataset below
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str32 SignFever str37 SignActivity str48 SignBreathing str49 SignFeeding str32 SignVomiting str48 SignStooling str44 SignSeizures str39 SignsColor float SignsOther "Spontaneous" "Spontaneous" "Spontaneous" "Prompted" "Prompted" "Prompted" "Prompted" "Spontaneous" 1 "Spontaneous" "Spontaneous" "Spontaneous" "Spontaneous" "Spontaneous" "Spontaneous" "Spontaneous" "Spontaneous" 0 "Spontaneous" "Prompted" "Not familiar with this risk sign" "Not familiar with this risk sign" "Not familiar with this risk sign" "Not familiar with this risk sign" "Prompted" "Prompted" 1 "Spontaneous" "Spontaneous" "Prompted" "Prompted" "Spontaneous" "Spontaneous" "Spontaneous" "Prompted" 0 "" "" "" "" "" "" "" "" . end label values SignsOther yesno5 label def yesno5 0 "No", modify label def yesno5 1 "Yes", modify
I have run encode with the following 2 codes
* Define a macro list of all variables with the same values
local sign_vars SignFever SignActivity SignBreathing SignFeeding SignVomiting SignStooling SignSeizures SignsOther SignsColor
foreach var of local sign_vars {
qui describe `var'
// Check if variable is string type
if "`r(typ)'" == "str" {
qui tab `var' if !missing(`var')
if r(N) > 0 {
encode `var', gen(`var'_encoded)
label define `var'_labels 1 "Spontaneous" ///
2 "Prompted" ///
3 "Not familiar with this sign"
label values `var'_encoded `var'_labels
drop `var'
rename `var'_encoded `var'
}
}
}
// Define a macro list of all variables to be encoded
local sign_vars SignFever SignActivity SignBreathing SignFeeding SignVomiting SignStooling SignSeizures SignsOther SignsColor
// Loop through each variable
foreach var of local sign_vars {
// Describe variable
qui describe `var'
// Check if variable is string type
if "`r(typ)'" == "str" {
// Tabulate non-missing values
qui tab `var' if !missing(`var')
// Check if there are non-missing values
if r(N) > 0 {
// Encode the variable
encode `var', gen(`var'_encoded)
// Define labels
label define `var'_labels 1 "Spontaneous" ///
2 "Prompted" ///
3 "Not familiar with this sign"
// Apply labels
label values `var'_encoded `var'_labels
// Drop original variable
drop `var'
// Rename encoded variable to original variable name
rename `var'_encoded `var'
}
}
}
At the end of each, and severally, it executes without any error messages but makes no changes to the dataset. They remain as string variables. What may be wrong please? I am using Stata 18
Obumneme Ezeanosike
Comment