echo 1
note macro table_2.obe
note This is a MLwiN macro to calculate means and standard deviations
note of variable Y grouped for values of variable X.
note Boxes B1 and B2 must be set to the column numbers
note of variables X and Y, respectively.
note Box B3 is the minimum number of cases per category.
note It is assumed that a variable "cons" is available
note of at least the same column length as X and Y.
note X-values are rounded to the nearest integer.
note Output is in the following columns:
note C411 : rounded X-value
note C412 : number of cases
note C413 : average of Y for these cases
note C414 : standard deviation of Y for these cases.
note C415 : standard error of the mean of Y for these cases.
note C416 : C413 - 2*C415
note C417 : C413 + 2*C415
note B3 must be at least 1.
note Columns C391-C397 are used as temporary variables.
note input values are
print b1 b2 b3
echo 0
note round and order X:
calc c391 = round(cb1)
sort c391 c392
note recode c392 into consecutive numbers:
mlre "cons" c392 c393
take c392 c393 c396 c397
count c397 b11
note There are b11 different values in c391
note These values are stored in c396
note Prepare variables:
set b18 0
put b11 0 C411
calc C412 = C411
calc C413 = C411
calc C414 = C411
calc C415 = C411
loop b12 1 b11
say .
pick b12 c396 b19
note b19 is the value of c391 that is now being treated
choose b19 c391 cb2 c394 c395
note c395 contains the Y-values associated with X = B19
count c395 b14
note b14 is the associated number of cases
calc b9 = sign(b14 - b3)
switch b9
case 0,1:
calc b18 = b18 + 1
aver c395 b14 b15 b16 b17
edit b18 C411 b19
edit b18 C412 b14
edit b18 C413 b15
edit b18 C414 b16
edit b18 C415 b17
endswitch
endloop
say \n
omit 0 C412 C411 C413-C415 C412 C411 C413-C415
erase c391-c397
echo 1
note Number of different rounded X-values with at least B3 cases is
print B18
note C411 : rounded X-value
note C412 : number of cases
note C413 : average of Y for these cases
note C414 : standard deviation of Y for these cases.
note C415 : standard error of the mean of Y for these cases.
calc C416 = C413 - 2*C415
calc C417 = C413 + 2*C415
mplot C413 C416 C417 C411