|
Hi all, I am trying to create binary variables with 1 being median of
a continuous variable or higher and zero being less than the median. I was
thinking it would be as easy as something like this: Comp Var1_binary=0. if(Var1 ge median(Var1)) Var1_binary=1. exe. I could not find anything like this in the syntax
manual. It seems like a basic type of functionality. I mean, if I can do it
easily in Excel why not SPSS? Any suggestions? Mark
|
|
Hi Mark You are on the right lines
except that using the median function will only give you the median value
across a number of variables *within* each case. I think you are looking for the
median for a given variable across all cases. Hence you need to create a new
variable with this value in and use that as the reference for each case … AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=base /median_var1=MEDIAN(Var1). Comp Var1_binary=0. If Var1 = median_var1
Var1_binary=1. … should do the trick HTH John From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of Mark.W.Andrews Hi all, I am trying to create binary variables with
1 being median of a continuous variable or higher and zero being less than the
median. I was thinking it would be as easy as something like this: Comp Var1_binary=0. if(Var1 ge
median(Var1)) Var1_binary=1. exe. I could not find anything like this
in the syntax manual. It seems like a basic type of functionality. I mean, if I
can do it easily in Excel why not SPSS? Any suggestions? Mark
|
|
In reply to this post by Mark.W.Andrews-2
Hi Mark:
This the closest solution I found,but it assigns 0 to values LE median, and 1 to values GT median, not exactly what you wanted (since you wanted LT median=0, GE Median=1): * Sample dataset *. DATA LIST FREE/copper(F8.2). BEGIN DATA 0.70 0.45 0.72 0.30 1.16 0.69 0.83 0.74 1.24 0.77 0.65 0.76 0.42 0.94 0.36 0.98 0.64 0.90 0.63 0.55 0.78 0.10 0.52 0.42 0.58 0.62 1.12 0.86 0.74 1.04 0.65 0.66 0.81 0.48 0.85 0.75 0.73 0.50 0.34 0.88 END DATA. VARIABLE LABEL copper 'Urinary copper (µmol/24hr)'. * Binary recode *. RANK VARIABLES=copper (A) /NTILES (2) into Var1_binary. COMPUTE Var1_binary=Var1_binary-1. * Label new variable and check results *. VALUE LABEL Var1_binary 0'LE Median' 1'GT Median'. FREQUENCIES VARIABLES=Var1_binary. HTH, Marta GG Mark.W.Andrews wrote: > > Hi all, > > > > I am trying to create binary variables with 1 being median of a > continuous variable or higher and zero being less than the median. I > was thinking it would be as easy as something like this: > > > > *Comp Var1_binary=0.* > > *if(Var1 ge median(Var1)) Var1_binary=1.* > > *exe.* > > * * > > I could not find anything like this in the syntax manual. It seems > like a basic type of functionality. I mean, if I can do it easily in > Excel why not SPSS? > > > ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by John McConnell-2
Minor clarification. In releases prior to
17, you need to create break variable that is a constant first, because in
previous releases Aggregate required a break variable (like “base”
in your example), as in: data list free /var1. begin data 1 2 3 4 5 6 7 8 9 10 end data. compute constant=1. aggregate /break=constant /medianvar=median(var1). compute
var1_binary=var1>=medianvar. list. In release 17 or later, no break variable
is required, and so you don’t need to create a constant or specify the
Break subcommand. From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of John McConnell Hi Mark You are on the right lines except that
using the median function will only give you the median value across a number
of variables *within* each case. I think you are looking for the median
for a given variable across all cases. Hence you need to create a new variable
with this value in and use that as the reference for each case … AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=base /median_var1=MEDIAN(Var1). Comp Var1_binary=0. If Var1 = median_var1 Var1_binary=1. … should do the trick HTH John From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of Mark.W.Andrews Hi
all, I
am trying to create binary variables with 1 being median of a continuous
variable or higher and zero being less than the median. I was thinking it would
be as easy as something like this: Comp Var1_binary=0. if(Var1 ge
median(Var1)) Var1_binary=1. exe. I
could not find anything like this in the syntax manual. It seems like a basic
type of functionality. I mean, if I can do it easily in Excel why not SPSS? Any
suggestions? Mark
|
|
Administrator
|
In reply to this post by Mark.W.Andrews-2
Others have addressed the question of how to do a median-split. But so far, no-one has asked why you want to do it. I'll not go so far as to say one should never dichotomize a continuous variable, but very often it is not a good idea. There are lots of articles on the perils of categorizing continuous variables. E.g., take a look at Dave Streiner's "Breaking up is hard to do:The heartbreak of dichotomizing continuous data. You can find it by doing a Google Scholar search on <Streiner breaking up is hard to do>.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
| Free forum by Nabble | Edit this page |
