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

Re: repost: -cond()- function


From   Michel Camus <[email protected]>
To   [email protected]
Subject   Re: repost: -cond()- function
Date   Thu, 01 Jan 2004 11:48:26 -0500

My previous message was tainted by my new Year's hangover. Sorry about that.

How is your original variable "chol" coded? How are the "missing values" of "chol" coded, more specifically?

".gen cholcat = cond(chol,0,1,9)" codes "cholcat" properly if "chol" has missing values coded as "."
... but it does not code "9" if "chol" has "missing values" coded as "9".
The function used is described in Stata as : "cond(x,a,b,c): a if x evaluates to true (not 0), b if x evaluates to false (0), and c if x evaluates to missing (.)".
Your expression would not evaluate "chol==9" as "missing" but as "not 1", that is as "0".
I don't know if this helps. Hope it does.

Michel
========
Michel Camus wrote:


I experience the same "problem" as you do, Paul.
I believe it has to do with "binary logic". The logical condition ("chol") always evaluates to 0 or 1, and nothing else, it never evaluates to "9" even if the original variable does have "9" as one value. The same happens even if your missing values in "chol" were already coded as "." See http://www.stata.com/support/faqs/data/values.html by W. Gould on "Logical expressions and missing values". The way to have missing values is tocondition your expression as follows : .gen cholcat = cond(chol,0,1) if chol != 9
Then you would still have to replace the missing (".") by "9" however if that is what you want.

Michel Camus
===============================
VISINTAINER PAUL wrote:


I am reposting this message:
I have an integer variable that I would like to collapse into a dichotomous variable. Using the following statement:

.gen cholcat = cond(chol,0,1,9)

produces the same output as:

.gen cholcat = cond(chol,0,1)

The first statement continues to recode "missings" as 1, not 9. In order to capture the missings appropriately, I have to follow each -cond()- statement with a -replace- command.


Am I using the -cond()- function appropriately?

Thanks,

paul visintainer

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



--

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

Michel Camus, Ph.D.

Épidémiologue, Div. Biostatistique et épidémiologie, DGSESC, Santé Canada

Epidemiologist, Biostatistics and Epidemiology Div., HECSB, Health Canada

Courriel / e-mail : [email protected] <mailto:[email protected]>

Téléphone / phone : (514) 850-0157

Télécopieur / fax : (514) 850-0836

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~




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