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   "Maarten Buis" <M.Buis@fsw.vu.nl>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: new local macro from results of loop
Date   Wed, 30 May 2007 17:16:11 +0200

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 lvstknos "`lvstknos' `v'nbeg `v'nend"
}

Hope this helps,
Maarten

NB notice the absence of the equal sign in the local 
statement, this will protect you against strings that
are too long.

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Ronnie Babigumira
Sent: woensdag 30 mei 2007 16:35
To: statalist@hsphsun2.harvard.edu
Subject: st: new local macro from results of loop

Dear list

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"

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

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