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 on April 23, and its replacement, 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 <>
To   "" <>
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?


*   For searches and help try:

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