Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: new local macro from results of loop


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: new local macro from results of loop
Date   Wed, 30 May 2007 16:11:13 +0100

local lvstk cattle largeanims calves smallrums smallanims
 
foreach v of local lvstk {
 	egen `v'nbeg = sum(liv_begnum) if `v', by(houscode qtr)
 	egen `v'nend = sum(liv_endnum) if `v', by(houscode qtr)
	local new `new' `v'nbeg `v'nend 
}

Nick 
n.j.cox@durham.ac.uk 

Ronnie Babigumira
 
> I define a local macro lvstk below which contains variables I 
> would like to process further. For example
> 
> local lvstk "cattle largeanims calves smallrums smallanims"
> 
> foreach v of local lvstk {
> 	egen `v'nbeg = sum(liv_begnum) if `v', by(houscode qtr)
> 	egen `v'nend = sum(liv_endnum) if `v', by(houscode qtr)
> }
> 
> how do I automatically put the new variables being generated 
> into a new macro
> 
> say
> 
> local lvstknos "cattlenbeg cattlenend 
> ....and-all-the-other-stuff-coming-out-of-the-foreach-loop"

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index