For a start, a lot of that code seems redundant (i.e. unnecessary
typing!). If you assign zero values to ob and ow at the start, then half
the lines (all those starting with "replace ob=0" and "replace ow=0") could
be removed. Also, if (which I think you should do, to avoid potential
problems) you handle cases with missing values of bmi at the start (I
assume that "." denotes missing), then you could get rid of all the "& bmi
~=." bits, reducing the above Stata code (apart from handling of 'missing'
bmi) to something like:
replace ob=0
replace ow=0
replace ob=1 if age>=7.75 & age<8.25 & sex==0 & bmi>21.57
replace ow=1 if age>=7.75 & age<8.25 & sex==0 & bmi>18.35
replace ob=1 if age>=7.75 & age<8.25 & sex==1 & bmi>21.6
replace ow=1 if age>=7.75 & age<8.25 & sex==1 & bmi>18.44
replace ob=1 if age>=8.25 & age<8.75 & sex==0 & bmi>22.18
replace ow=1 if age>=8.25 & age<8.75 & sex==0 & bmi>18.69
replace ob=1 if age>=8.25 & age<8.75 & sex==1 & bmi>22.17
replace ow=1 if age>=8.25 & age<8.75 & sex==1 & bmi>18.76
It's a very long time since I used SPSS, and there could well be tidier
ways to do it in modern versions but, but from what I recall, if you want
to stick to that same sort of algorithm, I think you could convert each of
the main lines in the above Stata code to an SPSS DO IF ... COMPUTE ...
ENDIF construct. For example, the first main line in the above Stata code
would then become, for SPSS:
do if (age>=7.75 & age<8.25 & sex==0 & bmi>21.57)
compute ob=1
end if
[in most modern 3GL languages one can code something simply like:
if (age>=7.75 & age<8.25 & sex==0 & bmi>21.57) then ob=1 ]
However, I presume that the two age ranges specified in the code you posted
are just two 'of many', so the full code (to cover all child age ranges)
could be very lengthy and tedious to type, not to mention inefficient. In
most languages, there would be tidier, less tedious and more efficient ways
to achieve the same end that a long series of if...then statements - e.g.
by using some sort of 'look-up table' (e.g. in an array) for the bmi
thresholds for ob and ow.
For example, using SAS (with which I'm much more familiar), the whole
process (easily extendable for any number of 0.5 year wide age bands) could
be achieved with the following code:
data bmi (keep = age sex bmi ob ow) ;
array ob2(50,0:1) ;
array ow2(50,0:1) ;
ob2(16,0) = 21.57; ob2(16,1) = 21.60; ow2(16,0) = 18.35; ow2(16,1) =
18.44 ;
ob2(17,0) = 22.18; ob2(17,1) = 22.17; ow2(17,0) = 18.69; ow2(17,1) =
18.76 ;
set bmitest ;
agegroup = 2*round(age, 0.5) ;
ob = 0 ; ow = 0 ;
if bmi = . then do ; ob = . ; ow = . ; end ;
else do ;
if bmi > ob2(agegroup, sex) then ob = 1 ;
else if bmi > ow2(agegroup, sex) then ow = 1 ;
end ;
run ;
proc print noobs data = bmi ; run ;
Using a dummy set of test data created using the following code:
data bmitest ;
input age sex bmi ;
cards ;
7.9 0 21.58
7.9 1 21.60
7.8 0 18.40
7.8 1 18.40
8.3 0 17.00
8.3 1 22.20
;
run ;
... the output obtained is as follows:
age sex bmi ob ow
7.9 0 21.58 1 0
7.9 1 21.60 0 1
7.8 0 18.40 0 1
7.8 1 18.40 0 0
8.3 0 17.00 0 0
8.3 1 22.20 1 0
The above code is very straightforward, and I would imagine that there is
probably someone reading this who could easily translate it into 'modern
day SPSS' code for you. For each 0.5 year-wide age-group you wish to add,
just add the required bmi thresholds in a 'row' of four array assignment
statements (like the two rows in the above example), the first array index
being the 'agegroup' (double the mid-point of the age range) and the second
being sex (0 or 1). The one refinement you might want to add to the code
would be to 'capture' situations in which the ages specified in your data
were outside the range of ages covered by the program (or in which sex was
something other than 0 or 1!).
Sorry to be long-winded, but perhaps this may help a bit!
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice:
+44 (0) 1296 730225
Mediscience Services Fax:
+44 (0) 1296 738893
Twyford Manor, Twyford, E-mail:
Joh...@mediscience.co.uk
Buckingham MK18 4EL, UK
medis...@compuserve.com
----------------------------------------------------------------