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]

st: RE: How to run a loop on labels


From   "Impavido, Gregorio" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: How to run a loop on labels
Date   Wed, 3 Jul 2013 15:02:29 +0000

Alice,  try this

** begin example
foreach var of varlist * {
	local lab `: var label `var''
	local lab `: di subinstr("`lab'", "1", "Administrative Office", 1)'
	local lab `: di subinstr("`lab'", "2", "Economic Department", 1)'
	label var `var' "`lab'"
}
** end example

Notice the last 1 in -subinstr()-.  This assumes that you have either one "1" or a "2" in your labels, if you have more than one, it won't work. In case, try -help subinstr()-

Gregorio


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alice Guerra
Sent: Wednesday, July 03, 2013 10:24 AM
To: [email protected]
Subject: st: How to run a loop on labels

Dear Statalists,

I have a list of variables' names and corresponding labels:

x1 label: Total duration in 1
y1 label: Total people in 1
z1 label: Total costs in 1

x2 label: Total duration in 2
y2 label: Total people in 2
z2 label: Total costs in 2

1 corresponds to Administrative Office, and 2 to Economic Department.

How can I substitute the 1 with Administrative Office in all the labels of variables that end with 1? And, that is the same, how can I substitute the 2 with Economic Department in all the labels of variables that end with 2?

Is it possible to run a loop for labels?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

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


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