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, **statalist.org** is already up and running.

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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: Evaluating a set of conditions |

Date |
Wed, 16 Jun 2010 23:58:56 +0100 |

Martin makes key points here. I'd emphasise his last: internalising that true expressions evaluate to 1 and false to 0 is often most helpful. A first tutorial is at FAQ . . . . . . . . . . . . . . . . . . . . . . . True and false in Stata 2/03 What is true and false in Stata? http://www.stata.com/support/faqs/data/trueorfalse.html Nick n.j.cox@durham.ac.uk Martin Weiss " but I hardly ever use them because understanding them (or remembering them) usually takes longer then writing the 'lengthy' qualifiers." -cond- and -inrange- are among the most easily understood functions in Stata, if you want my take on this. Try Nick and coauthor`s http://www.stata-journal.com/sjpdf.html?articlenum=pr0016 tutorial on -cond- or http://www.stata-journal.com/sjpdf.html?articlenum=dm0026 on -inrange-. Also, you can multiply expressions which can be handy. So if you want the running sum only for the cars with bad to average repair record: *** sysuse auto, clear sort rep78 gen newvar=sum((rep78<=3)*price) l rep78 price newvar *** Thomas Speidel I realize this is a very broad question and no one solution can fit all problems. I am looking for more efficient or elegant alternatives to evaluate a set of conditions in Stata, than a lenghty if qualifier. E.g.: do something if A==1 & (B>2 & B<.) & (C==1 | D!=2) these expression can become lengthy and one can think of more elegant ways to come to the same results. cond and inrange are the first things that come to my mind that may (or may not) simplify the problem, but I hardly ever use them because understanding them (or remembering them) usually takes longer then writing the 'lengthy' qualifiers. To complicate matters one has to account for missing values. Admittedly, this question came about from the recent topic on missing values. If someone want to share an example, please do so. * * 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/

**References**:**st: Evaluating a set of conditions***From:*Thomas Speidel <thomas@tmbx.com>

**st: RE: Evaluating a set of conditions***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**st: RE: Evaluating a set of conditions** - Next by Date:
**st: RE: Evaluating a set of conditions** - Previous by thread:
**st: RE: Evaluating a set of conditions** - Next by thread:
**st: RE: Evaluating a set of conditions** - Index(es):