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: creating new variables with local macro contents
From
"Nelson, Carl" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: creating new variables with local macro contents
Date
Tue, 15 Feb 2011 10:43:35 -0600
Hello,
I am working with a data set 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 {
2. replace `input' = -`input'
3. }
. local quantity "grain sheep other `inputs' "
. macro list _quantity
_quantity: grain sheep other livestock material labor capital land
. gen profit = 0
. foreach y of quantity {
2. gen exp`y' = `y'* p`y'
3. replace profit = profit + exp`y'
4. }
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/