Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How do I put a value of a local macro into a variable label


From   Pamela Oliver <[email protected]>
To   [email protected]
Subject   Re: st: How do I put a value of a local macro into a variable label
Date   Fri, 27 Jan 2012 08:31:31 -0600

It is possible simply to write

local label something
label var varname " `label' "

I do this often, generally to create composite labels within loops. Example:

local b Black
local w White
local h Hispanic
local viol violence
local drug drug
local theft theft
local rob robbery

foreach r in b w h {
foreach c in v d t {
label var `r'`c'o "``r'' ``c'' arrest rate"
}
}

Note that there are double markers for the locals. `r' would refer to b w h, while ``r'' refers to Black White Hispanic. my variable names follow a standard format with the race indicator being a single letter and a shortened name of the offense being lengthened. I also have a system of prefixes and postfixes, so that the o for example is my symbol for rate, and I left a prefix out of this example. I might also at times create locals for prefixes or postfixes.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index