Signs of value in Stata

Some datasets are labeled with full lowercase, and I end up with charts and tables showing the results for Egypt, Jordan, and Saudi Arabia instead of the names of the countries in the top.

I guess a string function proper()can do something for me, but I don’t find the right way to write code for Stata 11 that will use all the value labels for this variable.

I basically need to run a function proper()for all variable value labels, and then assign them to a variable. Is it possible to use loops foreachand macros in Stata?

+5
source share
1 answer

. :

clear
drawnorm x, n(10)
gen byte v = int(4+x)
drop x
label define types 0 "zero" 1 "one" 2 "two" 3 "three" 4 "four" 5 "five" 6 "six"
label list types
label values v types

, , "v":

local varname v
local sLabelName: value label `varname'
di "`sLabelName'"

levelsof `varname', local(xValues)
foreach x of local xValues {
    local sLabel: label (`varname') `x', strict
    local sLabelNew =proper("`sLabel'")
    noi di "`x': `sLabel' ==> `sLabelNew'"
    label define `sLabelName' `x' "`sLabelNew'", modify
}

:

label list types
+6

All Articles