foreach v of var * {
local last = substr("`v'", -2, 2)
local last = cond("`last'" == "al", "Achievement Level",
"Scalescore")
local first = substr("`v'", 3, .)
local first = substr("`first'", 1, strpos("`first'", "_") - 1)
label var `v' "`first' `last'"
}
-----Original Message-----
Andy Baxter
I have a large data set in which the variable names reflect the subject
and metric of a specific test, e.g., a_alg1_ss is the "Algebra 1 Scale
Score."
All of the variable names have a common structure: a prefix of a_, a
test identifier string, and a suffix of _[metric of test, e.g., al for
achievement level or ss for scale score].
The current variable labels reflect the test metric, but not the test
identifier.
Here is a subset of the variables:
. describe a_alg1_ss a_alg1_al a_alg1rt1_ss a_alg1rt1_al
storage display value
variable name type format label variable label
------------------------------------------------------------------------
-------
a_alg1_ss int %8.0g Scalescore
a_alg1_al byte %8.0g Achievement Level
a_alg1rt1_ss int %8.0g Scalescore
a_alg1rt1_al byte %8.0g Achievement Level
I am trying to write syntax that will extract the test identifier from
the variable name and insert it into the variable label. I would like
to wind up with:
variable name variable label
a_alg1_ss alg1 Scalescore
a_alg1_al alg1 Achievement Level
a_alg1rt1_ss alg1rt Scalescore
a_alg1rt1_al alg1rt Achievement Level
My Stata version is:
.about
Stata/SE 9.2 for Windows
Born 20 Jul 2007
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/