Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: generate if [exp], otherwise


From   Ronán Conroy <rconroy@rcsi.ie>
To   "statalist hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: generate if [exp], otherwise
Date   Thu, 12 Aug 2004 11:56:49 +0100

on 12/08/2004 09:24, Mark Clatworthy at ClatworthyMA@Cardiff.ac.uk wrote:

> I would like to generate a newvar which is equal to
> variable y +1 if variable x
> is less than 5, but equal to variable y if variable x is greater than 5.


. gen newvar = y + (x < 5) if ~missing(x)

The logical statement (x < 5) evaluates to true (1) or false (0). Since it
is false when x is missing, the -if- statement is needed to keep newvar from
taking on values when it shouldn't.

Ronan M Conroy (rconroy@rcsi.ie)
Lecturer in Biostatistics
Royal College of Surgeons
Dublin 2, Ireland
+353 1 402 2431 (fax 2764)

--------------------
Just say no to drug reps
http://www.nofreelunch.org/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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