Discussion:
mediansplit per spss makro
(too old to reply)
tohenning
2006-08-02 07:32:57 UTC
Permalink
Hey everybody,

I have some probs with SPSS syntax again.

In principle, my prob is simple: i want to do a mediansplit on a
variable and obtain a new variable which equals 0 if case is under
median and equals 1 when case is over median.

I have tried a lot, but can't solve this prob.

maybe someone can help me, would be great.

thanks in advance,
thomas
baiyun
2006-08-02 07:56:25 UTC
Permalink
Hello,

You can try this:

Say your file is: yourfile.sav, and the variable is myvar:

* with OMS save median in a .sav file *.

get file = 'D:\temp\yourfile.sav'.

OMS
/select tables
/if commands= 'Frequencies' subtypes = 'Statistics'
/destination format = sav
outfile = 'D:\temp\output.sav'.
FREQUENCIES
VARIABLES=myvar /FORMAT=NOTABLE
/STATISTICS=MEDIAN
/ORDER= ANALYSIS .
omsend.

* prepare the output file *.

get file = 'D:\temp\output.sav'.

select if (var1 = 'Median').

REN VAR (var4 = m).

compute nobreak = 1.

save outfile = 'D:\temp\output.sav' KEEP nobreak m.

* go for it! *.

get file = 'D:\temp\yourfile.sav'.

compute nobreak = 1.

MATCH FILES /FILE=*
/TABLE='D:\temp\output.sav'/BY nobreak.


if (myvar < m) newvar = 0.
if (myvar > m) newvar = 1.

HTH

baiyun
Post by tohenning
Hey everybody,
I have some probs with SPSS syntax again.
In principle, my prob is simple: i want to do a mediansplit on a
variable and obtain a new variable which equals 0 if case is under
median and equals 1 when case is over median.
I have tried a lot, but can't solve this prob.
maybe someone can help me, would be great.
thanks in advance,
thomas
JKPeck
2006-08-02 11:59:37 UTC
Permalink
Here is an easy way, assuming you have a reasonably current SPSS
version. "accel" is the variable to split on.

compute one = 1.
AGGREGATE
/OUTFILE=*
MODE=ADDVARIABLES
/BREAK=one
/accel_median = MEDIAN(accel).
compute OverMedian = accel > accel_median.

If your SPSS version does not have the MODE keyword, you would need to
save the aggreate to a file and match it back.

HTH
Jon Peck
SPSS
Bruce Weaver
2006-08-02 11:44:06 UTC
Permalink
Post by tohenning
Hey everybody,
I have some probs with SPSS syntax again.
In principle, my prob is simple: i want to do a mediansplit on a
variable and obtain a new variable which equals 0 if case is under
median and equals 1 when case is over median.
I have tried a lot, but can't solve this prob.
maybe someone can help me, would be great.
thanks in advance,
thomas
You can use AGGREGATE to write the median yo want into the working data
file, and then compute a flag for below versus equal to or greater than
the median. Here's an example of how to get a median split on the
horsepower variable (horse) from the cars data file that ships with
SPSS. (This code requires a version of SPSS that allows AGGREGATE to
write the aggregated variable straight into the working data file. For
older versions, you'd have to write the aggregated variable out to
another file, then use MATCH FILES to bring it into the working data file.)

* ---------------------------------------- .
GET FILE='C:\Program Files\SPSS\Cars.sav'.

compute allrecs = 1.
aggregate
/break = allrecs
/medhorse = median(horse)
.

compute GEmedian = (horse GE medhorse).
MEANS
horse BY GEmedian /
CELLS MEAN COUNT STDDEV MIN MAX MEDIAN
.
* ---------------------------------------- .

Why do you want the median split, by the way? I ask because people
often use the resulting dichotomous variable as a predictor variable in
a regression model when they would be far better off using the original
continuous variable.
--
Bruce Weaver
***@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
Art Kendall
2006-08-02 13:47:22 UTC
Permalink
Dr. Weaver asks "why", and so do I. (although it seems he has had his
coffee and put the question in a nicer way.)

< on soapbox >
In the policy arena statisticians / methodologists prepend "median
split" with an adjective such as "dreaded", "infernal", "invidious".

As one wag psychologist put it "friends don't let friends do median splits".


Once upon a time there were two kinds of analysts/researchers. Good,
moral, praiseworthy ones who did ANOVA; and bad, immoral, disreputable
ones who did correlation/regression. Then due to Cohen and others it
became known that ANOVA was just a special case of correlation /
regression (glm).

People used median splits (and some still do) to force-fit their
analysis into an ANOVA rhetorical model/schema.

"Please pass the hammer, I want to put this nail with the twisty thing
around it into this board."

< off soapbox >

Art
Post by Bruce Weaver
Post by tohenning
Hey everybody,
I have some probs with SPSS syntax again.
In principle, my prob is simple: i want to do a mediansplit on a
variable and obtain a new variable which equals 0 if case is under
median and equals 1 when case is over median.
I have tried a lot, but can't solve this prob.
maybe someone can help me, would be great.
thanks in advance,
thomas
You can use AGGREGATE to write the median yo want into the working data
file, and then compute a flag for below versus equal to or greater than
the median. Here's an example of how to get a median split on the
horsepower variable (horse) from the cars data file that ships with
SPSS. (This code requires a version of SPSS that allows AGGREGATE to
write the aggregated variable straight into the working data file. For
older versions, you'd have to write the aggregated variable out to
another file, then use MATCH FILES to bring it into the working data file.)
* ---------------------------------------- .
GET FILE='C:\Program Files\SPSS\Cars.sav'.
compute allrecs = 1.
aggregate
/break = allrecs
/medhorse = median(horse)
.
compute GEmedian = (horse GE medhorse).
MEANS
horse BY GEmedian /
CELLS MEAN COUNT STDDEV MIN MAX MEDIAN
.
* ---------------------------------------- .
Why do you want the median split, by the way? I ask because people
often use the resulting dichotomous variable as a predictor variable in
a regression model when they would be far better off using the original
continuous variable.
tohenning
2006-08-02 17:24:38 UTC
Permalink
Hey Art,

I am absolutly common with you, there is in fact no real need for a
median split.....from a scientific point of view.
but please think of the business in market reseach....some clients are
not so familiar with statistical tests and so on....so a median split
seems to be more understandable....
sorry :)


thanks a lot...
thomas
Post by Art Kendall
Dr. Weaver asks "why", and so do I. (although it seems he has had his
coffee and put the question in a nicer way.)
< on soapbox >
In the policy arena statisticians / methodologists prepend "median
split" with an adjective such as "dreaded", "infernal", "invidious".
As one wag psychologist put it "friends don't let friends do median splits".
Once upon a time there were two kinds of analysts/researchers. Good,
moral, praiseworthy ones who did ANOVA; and bad, immoral, disreputable
ones who did correlation/regression. Then due to Cohen and others it
became known that ANOVA was just a special case of correlation /
regression (glm).
People used median splits (and some still do) to force-fit their
analysis into an ANOVA rhetorical model/schema.
"Please pass the hammer, I want to put this nail with the twisty thing
around it into this board."
< off soapbox >
Art
Post by Bruce Weaver
Post by tohenning
Hey everybody,
I have some probs with SPSS syntax again.
In principle, my prob is simple: i want to do a mediansplit on a
variable and obtain a new variable which equals 0 if case is under
median and equals 1 when case is over median.
I have tried a lot, but can't solve this prob.
maybe someone can help me, would be great.
thanks in advance,
thomas
You can use AGGREGATE to write the median yo want into the working data
file, and then compute a flag for below versus equal to or greater than
the median. Here's an example of how to get a median split on the
horsepower variable (horse) from the cars data file that ships with
SPSS. (This code requires a version of SPSS that allows AGGREGATE to
write the aggregated variable straight into the working data file. For
older versions, you'd have to write the aggregated variable out to
another file, then use MATCH FILES to bring it into the working data file.)
* ---------------------------------------- .
GET FILE='C:\Program Files\SPSS\Cars.sav'.
compute allrecs = 1.
aggregate
/break = allrecs
/medhorse = median(horse)
.
compute GEmedian = (horse GE medhorse).
MEANS
horse BY GEmedian /
CELLS MEAN COUNT STDDEV MIN MAX MEDIAN
.
* ---------------------------------------- .
Why do you want the median split, by the way? I ask because people
often use the resulting dichotomous variable as a predictor variable in
a regression model when they would be far better off using the original
continuous variable.
tohenning
2006-08-02 17:26:44 UTC
Permalink
Thanks you all for your advices.....

meanwhile, very funny, I found another method on my own....

you can do this median split very easy by the RANK function.....
there you can do automatically a median split that creates a new
variable with the two values......


thomas
Post by Bruce Weaver
Post by tohenning
Hey everybody,
I have some probs with SPSS syntax again.
In principle, my prob is simple: i want to do a mediansplit on a
variable and obtain a new variable which equals 0 if case is under
median and equals 1 when case is over median.
I have tried a lot, but can't solve this prob.
maybe someone can help me, would be great.
thanks in advance,
thomas
You can use AGGREGATE to write the median yo want into the working data
file, and then compute a flag for below versus equal to or greater than
the median. Here's an example of how to get a median split on the
horsepower variable (horse) from the cars data file that ships with
SPSS. (This code requires a version of SPSS that allows AGGREGATE to
write the aggregated variable straight into the working data file. For
older versions, you'd have to write the aggregated variable out to
another file, then use MATCH FILES to bring it into the working data file.)
* ---------------------------------------- .
GET FILE='C:\Program Files\SPSS\Cars.sav'.
compute allrecs = 1.
aggregate
/break = allrecs
/medhorse = median(horse)
.
compute GEmedian = (horse GE medhorse).
MEANS
horse BY GEmedian /
CELLS MEAN COUNT STDDEV MIN MAX MEDIAN
.
* ---------------------------------------- .
Why do you want the median split, by the way? I ask because people
often use the resulting dichotomous variable as a predictor variable in
a regression model when they would be far better off using the original
continuous variable.
--
Bruce Weaver
www.angelfire.com/wv/bwhomedir
Loading...