Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: multiple conditions using an if statement?


From   Michael Betz <betz.40@buckeyemail.osu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: multiple conditions using an if statement?
Date   Fri, 22 Feb 2013 23:13:25 +0000

Hi all--Is it possible to have multiple conditions using an if statement?

I'm trying to create several variables and sum all but two of them. 

Here's my code:

	foreach e in aborig afr asia can camer carber euro namer nonabor ocean samer{
		gen `e'_grt=pob_`e'+poc_`e'
		if "`e'"!="aborig" | "`e'"!="nonabor" replace sum_grt=sum_grt+`e'_grt		
		}

It executes, but does not perform the second part of the if command beyond the "or" operator ("`e'"!="nonabor"). It sums all the variables except the "aborig" one, but I need it to sum all the variables except both "aborig" and "nonabor". Am I doing something illegal here?

Thanks,
Mike


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index