An alternative in this case is
(max(d, l, u) == d) + 0.5 * (max(d, l, u) == u) + 0 * (max(d, l, u) == l)
No great advantage to that. Just another way to do it.
Nick
[email protected]
Tonya Cropper
> Thanks a lot Scott for the suggestion.
>
> You inverted the expression and true/false result in your
> cond command. But
> once I reversed it, it worked fine.
>
> gen w = cond(1, max(d, l, u) == d, cond(0, max(d,l,u) == l,
> .5)) should be
>
> gen w = cond(max(d, l, u) == d, 1, cond(max(d,l,u) == l, 0, .5))
>
>
> From "Scott Merryman" <[email protected]>
> To <[email protected]>
> Subject st: RE: Finding max value and then replace w/ code
> Date Sun, 18 Jul 2004 18:45:19 -0500
>
> --------------------------------------------------------------
> --------------
> ----
>
> The problem is that after the value of wMjIc is replaced with
> 0 it then
> becomes equal to the value of uc, and so it is replace with 0.5.
>
> It might be easier to use a nested cond() function:
>
>
> gen w = cond(1, max(d, l, u) == d, ///
> cond(0, max(d,l,u) == l, .5))
>
> When max(d,l,u) == d is true then w = 1; if the condition is
> false it is
> evaluated again against l. If this is true then w = 0; if it
> false then w =
> 0.5.
>
> Example:
>
>
> +-------------------------------------+
> | id dc lc uc |
> |-------------------------------------|
> 1. | 2 .4292084 1.381115 0 |
> 2. | 3 1.219148 1.172775 .8614816 |
> 3. | 5 0 1.858415 0 |
> 4. | 6 0 1.021858 .4441429 |
> 5. | 7 .9105099 1.041191 0 |
> +-------------------------------------+
>
> . gen w = cond(1, max(d, l, u) == d, cond(0, max(d,l,u) == l, .5))
>
> . l
>
> +-----------------------------------------+
> | id dc lc uc w |
> |-----------------------------------------|
> 1. | 2 .4292084 1.381115 0 0 |
> 2. | 3 1.219148 1.172775 .8614816 1 |
> 3. | 5 0 1.858415 0 0 |
> 4. | 6 0 1.021858 .4441429 0 |
> 5. | 7 .9105099 1.041191 0 0 |
> +-----------------------------------------+
>
>
> Hope this helps,
> Scott
*
* 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/