/*Decode label variable to string */
foreach x of varlist * {
local form: format `x'
if strpos("`form'", "s") == 0 {
local labeled: value label `x'
if "`labeled'" != "" {
decode `x', gen(`x'_2)
drop `x'
ren `x'_2 `x'
}
}
}
/*Change the numeric value to string and generate the variable label*/
local varlist
local labellist
foreach x of varlist * {
local form: format `x'
if strpos("`form'", "s") == 0 {
tostring `x', replace force
}
local varlist "`varlist' `x'"
local y: variable label `x'
local labellist "`labellist' `y'"
}
/*Add 1 line to accomodate the variable value
gen id = _n
local obs = c(N) + 1
set obs `obs'
replace id = 0 if id == .
sort id
drop id
forvalue i = 1 / `c(k)' {
gettoken vari varlist : varlist
gettoken labe labellist : labellist
replace `vari' = "`labe'" in 1
}