[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Cameron Hooper <[email protected]> |

To |
[email protected] |

Subject |
Re: st: RE: if command |

Date |
Tue, 18 Jan 2005 13:25:13 -0500 |

Nick Cox wrote:

-if- as a keyword is overloaded. The two ways of using -if- you exemplifyI have not been clear. I apologise. I completely agree that code should be readable.

are not equivalent -- unless you have

single observation datasets.

Let me explain. I am not looking for a way to exploit some unique aspect of my data to make my code more efficient. So for example,

gen var1 = (fpi == "big") + 2 * (fpi == "small")

works, but only for these particular values.

I am asking a more general question. In stata can I test a condition and as a result of this single test generate (or replace) more than one variable? All of Nick's examples generated one variable as the result of testing one logical expression. In Fortran I can write:

IF (X.GE.10) THEN

Y = 12

Q = 78

ENDIF

Test once, set two variables. The only way I know to do this in stata is

gen y = 12 if x == 10

gen q = 78 if x == 10

I have to test x twice. Is there a way in stata to only test the condition once? I understand that "if exp {}" will not work.

Thanks.

Cameron.

*

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

**References**:**st: RE: if command***From:*"Nick Cox" <[email protected]>

- Prev by Date:
**st: kdens2 and scat3 problems. More general graph problems.** - Next by Date:
**st: RE: kdens2 and scat3 problems. More general graph problems.** - Previous by thread:
**st: RE: if command** - Next by thread:
**RE: st: RE: if command** - Index(es):

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