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: Returning Labels based on values.


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Returning Labels based on values.
Date   Tue, 25 Oct 2011 16:57:27 +0100

Yes. See -help macro- and -help extended_fcn-. These are undoubtedly key places for programmers. There are pointers in [U] and [P], so you didn't look in the right places. 

foreach v of numlist 1/4 {
	local label : label (SEASON) `v' 

     ... if SEASON == `v', subtitle("`label'") 

}

Note that there is no need to check whether the label has been defined:

sysuse auto
local label : label (mpg) 42

In this case, there is no label, but the macro just contains the value. However, your variable must be numeric. 

Nick 
[email protected] 

Cook, Daniel E

For programming purposes, I'm wondering if there is a way to return the a label based on the value used to specify it.

For example, consider a data set with the following values and labels for the variable SEASON:

1 Winter
2 Spring
3 Summer
4 Fall

Now suppose I have a do file and I want to create a graph for the mean temperature of each season...so I write something like this:

foreach v of numlist 1/4 {

...create a graph if SEASON == `v'... of avg. temp.

}

Now - I want to label each graph using the value label of the season being specified. In other words, if the graph is for the Summer - I'd like to add the value label "Summer" as the title, caption, or perhaps within the filename. So I'm looking for something like this:

foreach v of numlist 1/4 {

local name getvaluelabel(`v', SEASON) //This function would return the label for a given value by specifying the variable or value label.

...create a graph if SEASON == `v'...title(`name')

}

I have looked everywhere for a way to do this but can't seem to find anything. Perhaps I am overlooking something.


*
*   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