Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to compute Median of variables?

1,437 views
Skip to first unread message

poole

unread,
Apr 5, 2004, 4:41:08 AM4/5/04
to
As far as I can tell, the only SPSS command that provides the Median is
Frequencies. However, this is only provided as the median value across
cases. What I need to obtain is the median value across a set of
variables, for each case.

SPSS allows one to compute the mean across variables (where the number
of variables, N, may vary from case to case):

Compute mean.a = mean (var.a1, var.a2, var.a3..., var.aN).

I wish SPSS would similarly allow the following:

Compute median.a = median (var.a1, var.a2, var.a3..., var.aN).
Compute median.b = median (var.b1, var.b2, var.b3..., var.bN).

... So that one could use the newly computed variables in further
computations:

Compute ab.diff = median.a - median.b.

Unfortunately, I can see no way to do this in SPSS.

Any suggestions?

Bruce Weaver

unread,
Apr 5, 2004, 9:15:58 AM4/5/04
to

Here's one way: Restructure the file from WIDE to LONG
using VARSTOCASES; then use AGGREGATE to compute the desired
median(s). I have a syntax file somewhere that does this,
but can't find it right now.

Cheers,
Bruce
--
Bruce Weaver
wea...@mcmaster.ca
www.angelfire.com/wv/bwhomedir/

Michael....@colostate.edu

unread,
Apr 5, 2004, 12:22:47 PM4/5/04
to

> Any suggestions?


One way to do this is a bit tedious, but pretty fast:

1) Put the values of the variables in a vector and sort
the vector within each case. See my code snippet for sorting
variables within cases at Raynald's site. (It's a long URL, so
just go to http://pages.infinit.net/rlevesqu/ and search on
"bubble" to get a link to the bubble-sort syntax.)

While sorting, you also would want to stick the missing values at the
end (or beginning) of the vector, and count the number of valid (non-
missing) values within the vector.

2) Find the median as the "middle" value among the nonmissing values
in the vector.
--
=-=-=-=-=-=-=-=-=-==-=-=-=
Mike Lacy, Ft Collins CO 80523
Clean out the 'junk' to email me.

poole

unread,
Apr 6, 2004, 8:20:57 AM4/6/04
to
Sorry, but I am not familiar with what a "vector" is in SPSS. Would you
be so kind as to write out the actual syntax for this, using the
variable list in my example below? (using var.a1, var.a2..., var.aN, and
var.b1, var.b2..., var.bN, to compute median.a and median.b)

Thank you in advance for teaching this to me!

poole

unread,
Apr 6, 2004, 8:28:21 AM4/6/04
to
Bruce, were you able to find that syntax? I am not familiar with either
of the commands, VARSTOCASES or AGGREGATE. Would you be so kind as to
write out the actual syntax for how to do this, using the variable list
in my example below? (using var.a1, var.a2..., var.aN, and var.b1,
var.b2..., var.bN, to compute median.a and median.b)

Thank you in advance for showing me how to do this!

Bruce Weaver

unread,
Apr 6, 2004, 10:57:25 AM4/6/04
to
poole wrote:
> Bruce, were you able to find that syntax? I am not familiar with either
> of the commands, VARSTOCASES or AGGREGATE. Would you be so kind as to
> write out the actual syntax for how to do this, using the variable list
> in my example below? (using var.a1, var.a2..., var.aN, and var.b1,
> var.b2..., var.bN, to compute median.a and median.b)
>
> Thank you in advance for showing me how to do this!
>

I've sent you an example via e-mail that you should be able
to adapt to fit your data.

poole

unread,
Apr 6, 2004, 1:35:19 PM4/6/04
to Michael....@colostate.edu
Michael:

OK, I looked into the VECTOR command and see why you suggested I use
that. Unfortunately, the variables I am actually doing this on don't
actually have the names I listed in my example (I was just using a
shorthand). Here is what I want to do, using the actual variable names
(which are measures of activity in sub-areas within each of the main
lobes of the brain):

Compute Temp.2
= median (L.sup.T, R.sup.T, L.mid.T, R.mid.T, [etc. more vars]).
Compute Front.2
= median (L.dlat.F, R.dlat.F, L.orb.F, L.orb.F, [etc. more vars]).

[I want to computer about 35 such medians, but SPSS does not
include MEDIAN under the COMPUTE command. (yet?)]

I need these new variables available in my data file, to use in
computations, such as:

Compute T_F.dif = Temp.m - Front.m.

Do you know of some way to do this? If so, I would greatly appreciate it.

Regards,
John Poole
UC San Francisco

0 new messages