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

Re: st: multiple if??


From   Richard J Stoll <[email protected]>
To   <[email protected]>
Subject   Re: st: multiple if??
Date   Sun, 11 May 2003 14:51:09 -0500 (CDT)

On Sun, 11 May 2003, Ted Anagnoson wrote:

> At 02:42 PM 5/11/03 -0400, you wrote:
> >Hi,
> >
> >I have the following problems
> >
> >I have variable index which takes values from 1-10
> >
> >I have variables demand1 - demand10
> >depending upon the value of index, I have to select the value of demand 1
> >
> >i.e.
> >
> >if index==1, dem1 = demand1
> >if index==2, dem1 = demand2
> >if index==3, dem1 = demand3
>
Could I make a general observation?

I realize that some Stata users may feel that solving this problem by the
following is a bit too much brute force:

gen dem1 = demand1 if index == 1
gen dem2 = demand2 if index == 2
.etc.

But let me suggest a couple of reasons why this type of solution may be
preferable:
1.	It is straightforward and quick to implement using the basic
facilities of most editors.
2.	It can be much more time consuming to devise and debug a more
elegant solution.
3.	When you look back at these statements, it is easy to see what is
happening.  The code for a more elegant solution may be much more
difficult to decipher when you look back at your .do file in six months.

I greatly appreciate the inventiveness of solutions to problems that are
routinely offered on statalist.  I have seen elegant solutions to problems
that cannot be solved in any simple straightforward fashion.  I have even
used some of these solutions myself.  But my point is that sometimes there
is a strong case for a quick, inelegant brute force solution.
------------------------------------------------------------------------
Richard J. Stoll, Professor of Political Science and
Associate Dean of Social Sciences * Rice University
Dept. Political Science MS 24 * P.O. Box 1892 * Houston TX 77251-1892
E-mail: [email protected] * Tel: 713-348-3362 * FAX: 713-348-5273


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index