Bookmark and Share

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: RE: creating new variables with local macro contents


From   "Nelson, Carl" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: RE: creating new variables with local macro contents
Date   Tue, 15 Feb 2011 11:54:15 -0600

Nick, 

Thank you. Yes it was just a matter of using the correct foreach syntax. Sorry for the silly mistake.

Carl Nelson

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Tuesday, February 15, 2011 10:49 AM
To: '[email protected]'
Subject: st: RE: creating new variables with local macro contents

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/

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index