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   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: How do I put a value of a local macro into a variable label
Date   Fri, 27 Jan 2012 15:02:21 +0000

This is good technique, but your problem has a different structure from the original poster's, in that you end up with two nested loops for a cross-combination of arguments. The original question called for going through two lists of arguments in parallel. 

Nick 
[email protected] 

Pamela Oliver

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