> I have this section of code that creates a new variable that is equal to
> the maximum value amongst three choices. I then replace the value of
> the new variable to equal to either one of three integers. However, I
> am getting the incorrect replacement in certain cases - when the max is
> between the Lc and the Uc variable and only when Uc is 0.
I think more readable code would be something like
gen w = .
replace w = 1 if D>=L & D>=U & !mi(D)
replace w = 0 if L>=D & L>=U & !mi(L)
replace w = 0.5 if U>=L & U>=D & !mi(U)
You should think carefully about inclusion / non-inclusion (>= vs. >) in
the above. The argmax is not unique when say D==L, and your code might
have problems with it just as mine does.
If w is indeed an integer (as you said in the introduction, but did
contrary to that in the code), you would store it more efficiently with
-byte-. Even the way it is defined, w can be stored as -float- without any
loss of precision since all of 0, 1 and 1/2 are stored accurately in the
binary presentation.
--- Stas Kolenikov
-- Ph.D. student in Statistics at UNC-Chapel Hill
- http://www.komkon.org/~tacik/ -- [email protected]
* This e-mail and all attachments to it are not intended to provide any
* reasonable point of view and was transmitted to you in error. It
* should be immediately deleted by all recipients unless they really
* enjoy communicating with the author :). Other restrictions apply.
*
* 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/