Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Evaluating a set of conditions

From   Thomas Speidel <>
Subject   st: Evaluating a set of conditions
Date   Tue, 22 Jun 2010 17:09:57 -0600

Following up on my previous post: here is an example for something I am trying to achieve in a nice/efficient/eleganty way.

I have a number of dummies: a, b, c, d, e (missing values do exist)
Disease=true if the following conditions are met:

1) a must be true AND
2) any two of b, c, d, e are true

As I said missing values are crucial, especially when evaluating the second condition.

My current program works, but I don't think it is efficient and it probably does things that are unnecessary:

egen anytwo = rowtotal(a b c d e), missing
egen missing = rowmiss(a b c d e)
replace anytwo = . if (anytwo==0 & missing>=2 & missing<.)
replace anytwo = . if (anytwo==1 & missing==1)
replace anytwo = . if (anytwo==1 & missing==3)
replace anytwo = . if (missing>=4)

gen disease = 1 if (a==1 & anytwo>=2 & anytwo<.)
replace disease = 0 if (a==1 & anytwo<2)
replace disease = 0 if a==0
replace disease =. if a==.

I tried to play around with cond, but I found it was making this much more complicated then it is. I know I am complicating my life more than I need to which is why I am looking for alternative solutions.

Thomas Speidel

*   For searches and help try:

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