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

From |
Richard Williams <Richard.A.Williams.5@nd.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Taking averages, etc. |

Date |
Wed, 17 Dec 2003 14:18:09 -0500 |

At 01:24 PM 12/17/2003 -0500, David Kantor wrote:

I have written about this previously, but I feel compelled to state this again. Some of us may find it confusing, but I always do these kinds of operations using nested cond() functions:I like this! It seems to do exactly what I had in mind in terms of being a counterpart to the SPSS DO IF command. I believe it is also very similar to how you would do this in Excel if you were trying to fit the formula into a cell instead of writing a macro. My only objection, as you also note, is that this syntax is harder to read than the SPSS counterpart, but splitting things up onto separate lines probably helps.

#delimit ;

gen Y =

cond(X1 == 1 & X2 == 3, 3,

cond(X3 == 2 & X4 == 17, 4,

5));

Actually, I made the mistake, not Fred :) But I think this underscores that it would be easy (at least for somebody like me) to make coding mistakes if there were a lot of conditions involved.As Fred wrote: gen y = 3 if X1==1 & X2==3 replace y = 4 if X1 !=1 & X2 !=3 & X3==2 & X4==17 replace y = 5 if X1 !=1 & X2 !=3 & X3 !=2 & X4 !=17 First, this needs a correction:

-------------------------------------------

Richard Williams, Associate Professor

OFFICE: (574)631-6668, (574)631-6463

FAX: (574)288-4373

HOME: (574)289-5227

EMAIL: Richard.A.Williams.5@ND.Edu

WWW (personal): http://www.nd.edu/~rwilliam

WWW (department): http://www.nd.edu/~soc

*

* 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**:**Re: st: RE: Taking averages, etc.***From:*Richard Williams <Richard.A.Williams.5@nd.edu>

**st: RE: Taking averages, etc.***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: Taking averages, etc.***From:*"de la Garza, Adrian" <ADelagarza@imf.org>

**Re: st: RE: Taking averages, etc.***From:*David Kantor <dkantor@jhu.edu>

- Prev by Date:
**Re: st: RE: Taking averages, etc.** - Next by Date:
**st: sysdir set for do-files or datasets ?** - Previous by thread:
**Re: st: RE: Taking averages, etc.** - Next by thread:
**re: st: Taking averages, etc.** - Index(es):

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