can I get a decile minimum returned

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

can I get a decile minimum returned

beny
For a given variable, is there an existing function or macro that will return
a single value that identifies the cut off for the top decile or any other N%?

Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

David Marso
Administrator
Look up RANK followed by MATCH FILES (FIRST/LAST functions).
beny wrote
For a given variable, is there an existing function or macro that will return
a single value that identifies the cut off for the top decile or any other N%?
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

John F Hall
In reply to this post by beny
Freq <varname(s)> /format notable /per 90.

[or any other combination of percentiles]


John F Hall (Mr)

Email:    [hidden email]
Website: www.surveyresearch.weebly.com





-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
beny
Sent: 12 October 2012 16:56
To: [hidden email]
Subject: can I get a decile minimum returned

For a given variable, is there an existing function or macro that will
return a single value that identifies the cut off for the top decile or any
other N%?





--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-ret
urned-tp5715616.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

beny
In reply to this post by David Marso
Using RANK and MATCH FILES, I can flag the record that defines the cut off to the decile.
What I don't understand, is how to output that value so it can be used as the input to a macro.

Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

David Marso
Administrator
This post was updated on .
You should specify what you think you require a MACRO to do.
One shameless obsolete hack I created a long time ago was to use WRITE to create a DEFINE macrobody !ENDDEFINE followed by INCLUDE (search the archives if you want details) but scripting is more powerful if you can transcend the possible synchronization issues.  I suspect some pythonista will chime in with something more 'graceful'.
It is really best to define the context in which you are contemplating the need to feed data values into a MACRO.  Either you simply don't understand the nature of macros (stupid little string concatenators/pasters/parsers) or you overestimate their utility.  If you are just beginning your foray into macros you would best back out and spend your time learning scripting  or the MATRIX language instead.
--
beny wrote
Using RANK and MATCH FILES, I can flag the record that defines the cut off to the decile.
What I don't understand, is how to output that value so it can be used as the input to a macro.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

beny
In reply to this post by John F Hall
Same problem I have with the RANK and MATCH FILE method.

This FREQ approach gives me the number I want, but it is in a report. Is it possible to have the value output by a function or macro so that it can be passed into a macro.
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

Jon K Peck
In reply to this post by beny
Macros are static and cannot take data or output values other than sometimes by a terrible hack.  If you want to use results or data in further syntax - macro or otherwise - you need to use Python programmability.  If you want to go that route, which requires installing the (free) Python Essentials either from the SPSS Community website or, with Statistics V21 via the installation media or download, I can help you with that.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        beny <[hidden email]>
To:        [hidden email],
Date:        10/12/2012 10:03 AM
Subject:        Re: [SPSSX-L] can I get a decile minimum returned
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Using RANK and MATCH FILES, I can flag the record that defines the cut off to
the decile.
What I don't understand, is how to output that value so it can be used as
the input to a macro.





--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-returned-tp5715616p5715619.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

Ruben Geert van den Berg
In reply to this post by beny
Dear Ben,

You need only 3 lines of Python to create a new variable holding this value. This variable will persist until you close SPSS or manually delete/redefine it. You could also render it as a classical macro but these are considered deprecated so I wouldn't recommend spending any time on that.

However, the command "spssaux.GetValuesFromXMLWorkspace()" renders a lot of values, some of which are a rather mysterious to me. I didn't find the help function very  readable. I would very much appreciate any suggestions/examples on how to use this command in a more elegant way.

Best,

Ruben

*Create test data.
new fil.
set seed 1.

input program.
loop id=1 to 100.
compute v1=rv.nor(100,15).
end case.
end loop.
end file.
end input program.
exe.

*Pass value into new Python variable.
begin program.
import spssaux
cmd = spssaux.CreateXMLOutput("FREQUENCIES v1/for not/perc 90.")
decile_10=spssaux.GetValuesFromXMLWorkspace(cmd,"Statistics")[5]
end program.

*Check.
begin program.
print "The tenth decile starts at score: "+str(decile_10)
end program.

> Date: Fri, 12 Oct 2012 09:20:12 -0700

> From: [hidden email]
> Subject: Re: can I get a decile minimum returned
> To: [hidden email]
>
> Same problem I have with the RANK and MATCH FILE method.
>
> This FREQ approach gives me the number I want, but it is in a report. Is it
> possible to have the value output by a function or macro so that it can be
> passed into a macro.
>
>
>
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-returned-tp5715616p5715621.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> 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
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

David Marso
Administrator
In reply to this post by Jon K Peck
"you need to use Python programmability."
Hmmm Jon, so Basic scripting is broken or non existent these days?
I was solving things like this LONG before python even existed as a language!

Jon K Peck wrote
Macros are static and cannot take data or output values other than
sometimes by a terrible hack.  If you want to use results or data in
further syntax - macro or otherwise - you need to use Python
programmability.  If you want to go that route, which requires installing
the (free) Python Essentials either from the SPSS Community website or,
with Statistics V21 via the installation media or download, I can help you
with that.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:   beny <[hidden email]>
To:     [hidden email],
Date:   10/12/2012 10:03 AM
Subject:        Re: [SPSSX-L] can I get a decile minimum returned
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



Using RANK and MATCH FILES, I can flag the record that defines the cut off
to
the decile.
What I don't understand, is how to output that value so it can be used as
the input to a macro.





--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-returned-tp5715616p5715619.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

Jon K Peck


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        David Marso <[hidden email]>
To:        [hidden email],
Date:        10/12/2012 12:28 PM
Subject:        Re: [SPSSX-L] can I get a decile minimum returned
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




"you *need *to use *Python *programmability."
Hmmm Jon, so Basic scripting is broken or non existent these days?

>>>Basic scripting remains the mediocre technology it always was.  Among other things, it has no access to the XML workspace and wouldn't know what to do with it if it did.  Basic scripting in SPSS was conceived of mainly for working with Viewer objects, which it did an okay job of for its time.  But that time has long since passed.


I was solving things like this LONG before python even existed as a
language!

>>>Python has been around since the 80's.  I solved problems in IBM 1401 assembly language in the 60's, but I moved on.


Jon K Peck wrote
> Macros are static and cannot take data or output values other than
> sometimes by a terrible hack.  If you want to use results or data in
> further syntax - macro or otherwise - you need to use Python
> programmability.  If you want to go that route, which requires installing
> the (free) Python Essentials either from the SPSS Community website or,
> with Statistics V21 via the installation media or download, I can help you
> with that.
>
>
> Jon Peck (no "h") aka Kim
> Senior Software Engineer, IBM

> peck@.ibm

> new phone: 720-342-5621
>
>
>
>
> From:   beny &lt;

> ben.yuhas@

> &gt;
> To:

> SPSSX-L@.uga

> ,
> Date:   10/12/2012 10:03 AM
> Subject:        Re: [SPSSX-L] can I get a decile minimum returned
> Sent by:        "SPSSX(r) Discussion" &lt;

> SPSSX-L@.uga

> &gt;
>
>
>
> Using RANK and MATCH FILES, I can flag the record that defines the cut off
> to
> the decile.
> What I don't understand, is how to output that value so it can be used as
> the input to a macro.
>
>
>
>
>
> --
> View this message in context:
>
http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-returned-tp5715616p5715619.html
>
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-returned-tp5715616p5715624.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

Richard Ristow
In reply to this post by beny
At 11:59 AM 10/12/2012, beny wrote:

>Using RANK and MATCH FILES, I can flag the record that defines the cut off to
>the decile. What I don't understand, is how to output that value so
>it can be used as the input to a macro.

As others have posted, there are ways; less elegant with macro, more
elegant with Python.

But, can you fill us in: why do you want to do this? What will the
macro do? I ask, because native SPSS is very powerful, and can get
many effects without needing to move data into the code (as putting a
value into a macro or a Python program does).

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

David Marso
Administrator
"why do you want to do this?"
Exactly the unanswered initial question I posed awhile back....
I suspect any downstream would be mere transformation related and ergo diddling with MACRO or python or anything else is simply a manifestation of knowledge deficiency WRT what is immediately available.
OP needs to clarify context!!!
----
Richard Ristow wrote
At 11:59 AM 10/12/2012, beny wrote:

>Using RANK and MATCH FILES, I can flag the record that defines the cut off to
>the decile. What I don't understand, is how to output that value so
>it can be used as the input to a macro.

As others have posted, there are ways; less elegant with macro, more
elegant with Python.

But, can you fill us in: why do you want to do this? What will the
macro do? I ask, because native SPSS is very powerful, and can get
many effects without needing to move data into the code (as putting a
value into a macro or a Python program does).

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

beny
In reply to this post by Richard Ristow

Several people have asked me to be more specific in what I am trying to accomplish.

I have a program that assigns individuals to several different segments.
The assignment is based upon multiple conditions IF (A > 85 & B=3 & C<=4) Segment=1. , etc.

One of the conditions, say A > 42, identifies the individuals who score in the top 15% for a given test.
Currently, for each new set of customers,  I compute the cutoff for the top 15% manually by looking at the frequency distribution. I would like to compute this cut off automatically.


 
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

David Marso
Administrator
In other words.  You really don't require a macro.  Nor do you require python or any scripting program.
You really require mere syntax of a relatively simple (almost trivial) nature.

RANK VARIABLES=age (A)  /NTILES(20).
SORT CASES BY age.
IF MISSING(NAGE) NAGE=99.
MATCH FILES / FILE * / BY NAGE / FIRST=TOPNAGE.
COMPUTE X85=(NAGE EQ 18) * age * topnage.
AGGREGATE OUTFILE * MODE=ADDVARIABLES/ BREAK / Cutoff85=MAX(x85).

beny wrote
Several people have asked me to be more specific in what I am trying to accomplish.

I have a program that assigns individuals to several different segments.
The assignment is based upon multiple conditions IF (A > 85 & B=3 & C<=4) Segment=1. , etc.

One of the conditions, say A > 42, identifies the individuals who score in the top 15% for a given test.
Currently, for each new set of customers,  I compute the cutoff for the top 15% manually by looking at the frequency distribution. I would like to compute this cut off automatically.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

beny
Thanks David.  
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

Art Kendall
In reply to this post by beny
If I recall correctly, a macro can read a variable in a file.
The example syntax below generates  deciles (/ntiles(10), and the highest and lowest score in the decile.
it also generates variables for every case with the limit scores on the chosen (here the 5th) decile.
that could be used in  syntax, a script, python, and most likely a macro.

OMS could be used to pull details from FREQUENCIES and add them as variables or tables for MATCH FILES.

Macros have been considered by many to be obsolete for some time.
if you describe what you were thinking of having the macro do some list members could suggest ways of accomplishing what you want to;
* simulate some data.
new file.
input program.
   loop id = 1 to 250.
      compute score = rnd(rv.normal(50,10)).
      end case.
   end loop.
   end file.
end input program.
*create 3 new variables per case.
* which ntile the case is in (decile in this example.
* the lowest score in the ntile.
* the highest score in th entile.
rank variables = score
   /ntiles(10) into my_ntile.
sort cases by my_ntile.
aggregate outfile= * mode=addvariables
   /break = my_ntile
   /ntile_min = min(score)
   /ntile_max = max(score).
do if my_ntile eq 5.
   compute chosen_ntile_score = score.
ELSE.
   compute chosen_ntile_score= -999.
end if.
missing values chosen_ntile_score (lo thru -1).
compute nobreak = 1.
aggregate  outfile= * mode=addvariables
   /break =  nobreak
   /chosen_ntile_min = min(chosen_ntile_score)
   /chosen_ntile_max = max(chosen_ntile_score).
list variables = all /cases from 1 to 250 by 20.



Art Kendall
Social Research Consultants
On 10/12/2012 12:20 PM, beny wrote:
Same problem I have with the RANK and MATCH FILE method.

This FREQ approach gives me the number I want, but it is in a report. Is it
possible to have the value output by a function or macro so that it can be
passed into a macro.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-returned-tp5715616p5715621.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: can I get a decile minimum returned

Art Kendall
Although the application it demonstrates is trivial the macro with the syntax below shows how a macro might use variables that exist in the file.
However, I have been using SPSS since 1972 on many studies in the social and behavioral sciences.  If I recall correctly macros have been around for a couple decades.  I have used them only 2 or three times. 
One reason list members have asked what you want to do with a macro is that these days they are rarely needed.
Things can be done in syntax, scripts, or python more readily.
define !testmac().
   dataset activate madeup.
   display dictionary.
   compute width_chosen_decile = chosen_ntile_max - chosen_ntile_min.
   compute width_this_decile = ntile_max - ntile_min.
   compute width_comparison = width_this_decile - width_chosen_decile.
   formats width_chosen_decile width_chosen_decile width_comparison (f2).
   sort cases by my_ntile.
   dataset declare aggfile.
  
   aggregate outfile= aggfile /break=my_ntile
   /width_this_decile = first(width_this_decile)
   /width_chosen_decile = first(width_chosen_decile)
   /width_comparison = first (width_comparison).
      dataset activate aggfile.
      list.
   !enddefine.
* simulate some data.
new file.
input program.
   loop id = 1 to 250.
      compute score = rnd(rv.normal(50,10)).
      end case.
   end loop.
   end file.
end input program.
dataset name madeup.
*create 3 new variables per case.
* which ntile the case is in (decile in this example.
* the lowest score in the ntile.
* the highest score in th entile.
rank variables = score
   /ntiles(10) into my_ntile.
sort cases by my_ntile.
aggregate outfile= * mode=addvariables
   /break = my_ntile
   /ntile_min = min(score)
   /ntile_max = max(score).
do if my_ntile eq 5.
   compute chosen_ntile_score = score.
ELSE.
   compute chosen_ntile_score= -999.
end if.
missing values chosen_ntile_score (lo thru -1).
compute nobreak = 1.
aggregate  outfile= * mode=addvariables
   /break =  nobreak
   /chosen_ntile_min = min(chosen_ntile_score)
   /chosen_ntile_max = max(chosen_ntile_score).
list variables = all /cases from 1 to 250 by 20.
!testmac.

Art Kendall
Social Research Consultants
On 10/21/2012 10:34 AM, Art Kendall wrote:
If I recall correctly, a macro can read a variable in a file.
The example syntax below generates  deciles (/ntiles(10), and the highest and lowest score in the decile.
it also generates variables for every case with the limit scores on the chosen (here the 5th) decile.
that could be used in  syntax, a script, python, and most likely a macro.

OMS could be used to pull details from FREQUENCIES and add them as variables or tables for MATCH FILES.

Macros have been considered by many to be obsolete for some time.
if you describe what you were thinking of having the macro do some list members could suggest ways of accomplishing what you want to;
* simulate some data.
new file.
input program.
   loop id = 1 to 250.
      compute score = rnd(rv.normal(50,10)).
      end case.
   end loop.
   end file.
end input program.
*create 3 new variables per case.
* which ntile the case is in (decile in this example.
* the lowest score in the ntile.
* the highest score in th entile.
rank variables = score
   /ntiles(10) into my_ntile.
sort cases by my_ntile.
aggregate outfile= * mode=addvariables
   /break = my_ntile
   /ntile_min = min(score)
   /ntile_max = max(score).
do if my_ntile eq 5.
   compute chosen_ntile_score = score.
ELSE.
   compute chosen_ntile_score= -999.
end if.
missing values chosen_ntile_score (lo thru -1).
compute nobreak = 1.
aggregate  outfile= * mode=addvariables
   /break =  nobreak
   /chosen_ntile_min = min(chosen_ntile_score)
   /chosen_ntile_max = max(chosen_ntile_score).
list variables = all /cases from 1 to 250 by 20.



Art Kendall
Social Research Consultants
On 10/12/2012 12:20 PM, beny wrote:
Same problem I have with the RANK and MATCH FILE method.

This FREQ approach gives me the number I want, but it is in a report. Is it
possible to have the value output by a function or macro so that it can be
passed into a macro.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/can-I-get-a-decile-minimum-returned-tp5715616p5715621.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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

===================== 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
Art Kendall
Social Research Consultants