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
[email protected]
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/