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

RE: st: multiple if??


From   "Ed Bassin, Ph.D." <[email protected]>
To   <[email protected]>
Subject   RE: st: multiple if??
Date   Sun, 11 May 2003 14:56:15 -0400

you could use a single generate statement with nested "cond", e.g.,
	gen
dem1=cond(index==1,demand1,cond(index==2,demand2,cond(index==3,demand3...


-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Ted Anagnoson
Sent: Sunday, May 11, 2003 2:47 PM
To: [email protected]
Subject: Re: st: multiple if??


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

Try something like:

gen dem1 = demand1 if index == 1
or, if dem1 already exists,
replace dem1 = demand1 if index == 1

General rule:
If statements go after the relevant command in Stata, and before the comma
the delimits the command portion from the options portion....

Ted Anagnoson
Political Science
California State University, Los Angeles


>...
>
>and so on
>
>Is there any easy way (or a single command) to do this
>
>Thanks,
>
>Prabhu
>*
>*   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/

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

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