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]

Re: st: Overlapping Loops


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: Overlapping Loops
Date   Wed, 18 Jan 2012 13:44:34 -0600

numberofpeople`i' is not a number.

Have locals numberofpeople1 - numberofpeople17 previously been defined?

Perhaps something like this:

local number1 = 2
local number2= 3
local number3= 1

forvalues i = 1/3 {
	forvalues j=1/`number`i'' {
	disp `i' "  " `j'
}
}


Scott

On Wed, Jan 18, 2012 at 1:26 PM, Bader Alhashel <[email protected]> wrote:
> I am trying to write two over lapping "foreach" loops however I keep
> getting an invalid syntax error. I don't know why but I am guessing it
> is because of the local macro in the first loop is not recognized in
> the second loop. This is the code I am trying to run.
>
> forvalues i = 1/17 {
> gen ceo_photo`i'=0 if photo`i'==1
> forvalues j=1/numberofpeople`i' {
> replace ceo_photo`i'=1 if ceo == name`j'_photo`i' & ceo_photo`i'==0
> }
> }
>
> Your help would be greatly appreciated,
> Bader
> *
> *   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