Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: dump variable label value into local macro??


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: dump variable label value into local macro??
Date   Tue, 15 Nov 2005 23:26:22 -0000

The immediate problem was solved, but the code shows
confusion on a basic point. Removing secondary detail, 
you had 

local i = 1
forvalues i = 1(1)9 {
	gr hbar (mean) ... if segment2==`i' 
	graph export m_error`i'.pdf, replace
 	local i = `i' + 1
}

The initialization 

	local i = 1 

and the incrementation

	local i = `i' + 1 

are both irrelevant to the -forvalues- loop. 
-forvalues- initialises and increments its own counter, 
regardless. Otherwise put, 

forval i = 1/9 { 
	...
} 

is equivalent to, but faster than, 

local i = 1
while `i' <= 9 { 
	...
	local i = `i' + 1
} 

Nick 
[email protected] 

[email protected]

> I am -forvalue-ing across values of a categorical variable w/ nine
> unique values and generating a graph for each unique value of this
> variable.  This variable is numeric and i've attached a label to each
> value of this variable via -label define- and -label values-. When
> generating the graphs, I would like to use the -subtitle-
> option to denote which level of the categorical variable is being
> graphed, albeit i want the actual label value written to the 
> graph, not
> the value of the macro.  The abbreviated syntax follows:
> local i = 1
> forvalues i = 1(1)9 {
> gr hbar (mean) mean_abs_error mean_error_to_itd count_abs_error if
> segment2==`i' , ///
> subtitle("`i'") legend(off) ytitle("Absolute Error, 
> Relative Error, &
> Project Num.") ///
> graph export m_error`i'.pdf, replace
> local i = `i' + 1
> }

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index