| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: RE: new local macro from results of loop
hmmm, having just given this answer I am now looking at a program of mine that I am trying to debug and I seem to run into a problem where the solution I have just given does not work. Here is a an excerpt from my trace:
- if `i' == `trans' {
= if 2 == 2 {
- di `eqnsdenom'
= di
- local eqnsdenom `eqnsdenom' `equ'
= local eqnsdenom 2
- di `eqnsdenom'
= di <-- I would have expected this to read: di 2
- local k = `j' - 1
= local k = 2 - 1
- if `choice' == `k' {
= if 1 == 1 {
- local eqnum = `equ'
= local eqnum = 2
- }
- }
- local `equ++'
= local 2
- }
- if `i' == `trans' {
= if 2 == 2 {
- di `eqnsdenom'
= di <-- I would have expected this to read: di 2
- local eqnsdenom `eqnsdenom' `equ'
= local eqnsdenom 3 <-- I would have expected this to read: local eqnsdenom 2 3
- di `eqnsdenom'
= di <-- I would have expected this to read: di 2 3
-----------------------------------------
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: [email protected] [mailto:[email protected]]On Behalf Of Maarten Buis
Sent: woensdag 30 mei 2007 17:16
To: [email protected]
Subject: st: RE: new local macro from results of loop
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: [email protected] [mailto:[email protected]]On Behalf Of Ronnie Babigumira
Sent: woensdag 30 mei 2007 16:35
To: [email protected]
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/
*
* 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/