If teapd, teapwk or teapmth are left blank (i.e. missing), the logic may fail. The > and < comparisons cannot be guaranteed to work with missing values because EpiData does not like logic with missing values (e.g. "missing" AND false). If you turn on the option to flag all computational errors at Entry time, you will see the error.
Your logic is correct for the situation when a number is entered for ALL 3 fields.
I'm surprised that your second solution works - I've never seen more than one BEFORE ENTRY block in a field.
If unused entries are left blank, use the same logic but like this:
IF ((teapd<>.) and (teapwk<>.)) or ... THEN
Here is something you can do.
For TEAPD, TEAPWK and TEAPMTH, include:
AFTER ENTRY IF (teapd=.) then teapd = -1 ENDIF END
This ensures that the missing value -1 is entered.
In the BEFORE ENTRY block, you will also want to put something like:
IF ... THEN HELP "Only one of ..." GOTO teapd ENDIF
Otherwise, you can just ignore the help message and carry on.
I would probably have made the .qes look like this:
teafreq ## teaper ## (1=day, 7=week, 30=month)
This avoids the need for logic.
Jamie
On 2011-09-08, Suzanna wrote:
Is it possible to combine AND and OR into a single IF statement. If so, how? I have variables for the number of cups of tea consumed per day/week/month. The 3 variables are teapd, teapwk and teapmth. Only one of these should be filled in. -1 is the missing code and a value>0 indicates the number of cups consumed.