Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: creating new variables with local macro contents
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: creating new variables with local macro contents
Date
Tue, 15 Feb 2011 16:49:27 +0000
What was the problem reported? The second loop should start
foreach y of local quantity {
Nick
[email protected]
Nelson, Carl [edited]
I am working with a dataset that has quantity variables named like -capital- and -labor-, and price variables named -pcapital- and -plabor-. I am trying to use -foreach- loops to create expenditures and their sums but my syntax is wrong. I'd appreciate suggestions to fix my syntax. The example follows:
local inputs "livestock material labor capital land"
foreach input of local inputs {
replace `input' = -`input'
}
local quantity "grain sheep other `inputs' "
gen profit = 0
foreach y of quantity {
gen exp`y' = `y'* p`y'
replace profit = profit + exp`y'
}
Carl Nelson
University of Illinois
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/