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

Re: st: generate if [exp], otherwise


From   Chris Wallace <c.wallace@qmul.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: generate if [exp], otherwise
Date   Thu, 12 Aug 2004 09:25:20 +0100

Chris Wallace <c.wallace@qmul.ac.uk> writes:

> "Mark Clatworthy" <ClatworthyMA@Cardiff.ac.uk> writes:
>
>> 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.  
>
> one way:
>
> gen newvar=y
> replace newvar=y+1 if x>5 & x<.

sorry - wrong way round.

gen newvar=y
replace newvar=y+1 if x<5

C.

*
*   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