Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: if programming command


From   Paul Seed <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: if programming command
Date   Fri, 10 Oct 2008 16:07:04 +0100

There is one more problem with Lou's code, apart from the points made by Nick Cox & Nick Winter : -replace syphilis = 1- is a valid command; but -replace syphilis == 1- is not. -syphilis == 1- is a statement, that is either true or false, and can be evaluated for every value of syphilis.

As Nick Winter points out, the last section will always resolve to 1; meaning TRUE.
How Lou shold change it depends on what he actually means.
If Lou intends -syphilis- to exclude those subjects with -lbresc- either
"POSITIVE 1:128" or  "POSITIVE 1:16", he needs

replace syphilis=1 if visit==1 & lbcd=="SYP_RPR" & (lbresc!="POSITIVE 1:128" & lbresc!="POSITIVE 1:16")

If Lou intends to include subjects with these two values of -lbresc-, he needs

replace syphilis=1 if visit==1 & lbcd=="SYP_RPR" & (lbresc=="POSITIVE 1:128" | lbresc =="POSITIVE 1:16")

BW
Paul  Seed

Date: Thu, 9 Oct 2008 08:55:17 -0700 (PDT)
From: lou apicella <[email protected]>
Subject: st: if programming command

Hello Statalisters,

I'm trying to convert some logical statements into nested if statements. I feel the two statements below should give the same result but they do not. What am I do wrong here?

Thanks in advance.

Lou.

replace syphilis=1 if visit==1 & lbcd=="SYP_RPR" & (lbresc!="POSITIVE 1:128" | lbresc!="POSITIVE 1:16")



if visit==1 {
if lbcd=="SYP_RPR" & (lbresc!="POSITIVE 1:128" | lbresc!="POSITIVE 1:16" ) {
               replace syphilis==1
    }
}




Paul T Seed MSc CStat, Lecturer in Medical Statistics,
tel  (+44) (0) 20 7188 3642, fax (+44) (0) 20 7620 1227
Wednesdays: (+4) (0) 20 7848 4148

[email protected], [email protected]

King's College London, Division of Reproduction and Endocrinology
St Thomas' Hospital, Westminster Bridge Road, London SE1 7EH




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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