Deleting Variables

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

Deleting Variables

Nyougo Omae.
Hello,

Is there a way of deleting variables whose names start or end with a common phrase without doing it individually? (eg gf_01, gf_2 ... or  ws_gf , tk_gf?

Thanks.

Nyougo

=====================
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: Deleting Variables

Hal 9000
Here's how I'd do it:
*****************.
new file.
data list free
        /v1 (a10).
begin data
'gf_2'
'bf_2'
'gf_3'
'bf_3'
'gf_4'
'ws_gf'
'ab_gf_cd'
'tk_gf'
'tk_bf'
end data.

compute has_gf = index(v1, 'gf') > 0.
exe.

select if has_gf.
exe.

*****************.

On Nov 14, 2007 8:10 AM, Nyougo Omae. <[hidden email]> wrote:

> Hello,
>
> Is there a way of deleting variables whose names start or end with a common phrase without doing it individually? (eg gf_01, gf_2 ... or  ws_gf , tk_gf?
>
> Thanks.
>
> Nyougo
>
> =====================
> 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
|

Cluster Analysis

Pirritano, Matthew
Can someone tell me if it is possible to do the average linkage method in SPSS? I'm getting conflicting reports that you can't or that it is the same as the centroid method.

Thanks,

Matthew Pirritano, Ph.D.
Assistant Professor of Psychology
Smith Hall 116C
Chapman University
Department of Psychology
One University Drive
Orange, CA 92866
Telephone (714)744-7940
FAX (714)997-6780

=====================
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: Deleting Variables

Kulvinder Singh
In reply to this post by Nyougo Omae.
You can specify the variables in your syntax with delete command

Syntax:

Delete Variables <Var1 name> <Var2 name> <Var3 name> <Var4 name> <Var4
name>  <Var..n name>.
exe.

Example:

Delete Variables Var1 Var2 Var3 Var4 Var5.
exe.


Kulvinder

=====================
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: Cluster Analysis

Art Kendall
In reply to this post by Pirritano, Matthew
Average linkage is the default in SPSS.  If you do not use the METHOD
subcommand, that is what is used.

The centroid method is different.  Specify  /METHOD = CENTROID.

Depending what your goals are,  it is often a good idea to use a few
different proximity measures and agglomeration methods to and work with
sets of cases that are put together by several methods.

If you are using hierarchical methods just to get a "slice" of the tree,
the TWOSTEP method gives you the AIC and BIC for number-of-clusters
solutions in a range you specify.


Art Kendall
Social Research Consultants



Pirritano, Matthew wrote:

> Can someone tell me if it is possible to do the average linkage method in SPSS? I'm getting conflicting reports that you can't or that it is the same as the centroid method.
>
> Thanks,
>
> Matthew Pirritano, Ph.D.
> Assistant Professor of Psychology
> Smith Hall 116C
> Chapman University
> Department of Psychology
> One University Drive
> Orange, CA 92866
> Telephone (714)744-7940
> FAX (714)997-6780
>
> =====================
> 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: Cluster Analysis

Melissa Ives
In reply to this post by Pirritano, Matthew
Matthew,

Since the possibilities for various commands can change with versions,
your (and other's) best bet would be to search the SPSS help/syntax help
to see what is possible in your version.   So there is between group
(the default) and within group average--your choice.

By typing CLUSTER in a syntax window and then clicking on the Syntax
Help icon, I get:

[/METHOD={BAVERAGE**}[(rootname)] [...]]
         {WAVERAGE  }
         {SINGLE    }
         {COMPLETE  }
         {CENTROID  }
         {MEDIAN    }
         {WARD      }
         {DEFAULT** }

Then choosing the "METHOD Subcommand (CLUSTER command)
<mk:@MSITStore:c:\program%20files\spss14\help\main\spsswin.chm::/syn_clu
ster_method.htm> " under Related topics, I get--


METHOD Subcommand (CLUSTER command)

METHOD (subcommand),METHOD (subcommand),METHOD (subcommand)
CLUSTER command,CLUSTER command,CLUSTER command
Hierarchical Cluster Analysis,Hierarchical Cluster Analysis,Hierarchical
Cluster Analysis
methods,methods,methods

METHOD specifies one or more clustering methods.

*       If the METHOD subcommand is omitted or included without
specifications, the method of average linkage between groups is used.
*       Only one METHOD subcommand can be used, but more than one method
can be specified on it.
*       When the number of items is large, CENTROID and MEDIAN require
significantly more CPU time than other methods.

BAVERAGE         Average linkage between groups (UPGMA). BAVERAGE is the
default and can also be requested with keyword DEFAULT.
WAVERAGE         Average linkage within groups.
SINGLE   Single linkage or nearest neighbor.
COMPLETE         Complete linkage or furthest neighbor.
CENTROID         Centroid clustering (UPGMC). Squared Euclidean
distances are commonly used with this method.
MEDIAN   Median clustering (WPGMC). Squared Euclidean distances are
commonly used with this method.
WARD     Ward's method. Squared Euclidean distances are commonly used
with this method.


Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Pirritano, Matthew
Sent: Thursday, November 15, 2007 1:29 AM
To: [hidden email]
Subject: [SPSSX-L] Cluster Analysis

Can someone tell me if it is possible to do the average linkage method
in SPSS? I'm getting conflicting reports that you can't or that it is
the same as the centroid method.

Thanks,

Matthew Pirritano, Ph.D.
Assistant Professor of Psychology
Smith Hall 116C
Chapman University
Department of Psychology
One University Drive
Orange, CA 92866
Telephone (714)744-7940
FAX (714)997-6780

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




PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
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: Deleting Variables

Hal 9000
In reply to this post by Kulvinder Singh
Right....values, variables....whatever.

Sorry about that....this code (untested), or something very similar,
ought to do the trick:

***********************.
new file.
data list free /v1_gf v2_bf v3_gf.
begin data
1 2 3
end data.

set mprint on mexpand on printback on.
define @D (Z = !charend('/'))
!do !V !in (!Z)
!if (!index(!eval(!V), 'gf') > 0) !then
delete variables !V.
!ifend
!doend
!enddefine.

@D Z = v1_gf v2_bf v3_gf/.
***********************************.

On Nov 15, 2007 1:59 AM, Kulvinder Singh <[hidden email]> wrote:

> You can specify the variables in your syntax with delete command
>
> Syntax:
>
> Delete Variables <Var1 name> <Var2 name> <Var3 name> <Var4 name> <Var4
> name>  <Var..n name>.
> exe.
>
> Example:
>
> Delete Variables Var1 Var2 Var3 Var4 Var5.
> exe.
>
>
> Kulvinder
>
>
> =====================
> 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: Deleting Variables

Keith McCormick
In reply to this post by Kulvinder Singh
Hello,

I found this one interesting. If I am understand it correctly, Hal's
solution deletes DATA that meets the criterion, and Kulvinder's
requires that the name be spelled out in full. Alas, I don't have the
complete answer as there is an error in my code. Perhaps one of the
very good coders on the list can figure it out!

*python_delete_variable .
BEGIN PROGRAM.
import spss
NumVar = spss.GetVariableCount()
for i in range(NumVar):
        name=spss.GetVariableName(i)
        if name.lower()[:3] =="nat":
                spss.Submit("Delete Variable " + name)
END PROGRAM.

The key is that [0:3] or simply [:3] indicates the first three chars
of the variable NAME. Note that [-3:] would be the last three; [-2:]
would be the last two.

The problem is that once the variable is deleted the index changes, so
that it deletes EVERY OTHER instance of a variable that starts with
NAT. I just couldn't fix it.

Although flawed, it shows, I think , the main difference between
syntax and python. Syntax is very good at manipulating data, but
struggles with "meta data".

If anyone can fix the code, please post. I will try to fix it myself.

Keith
www.keithmccormick.com




On 11/15/07, Kulvinder Singh <[hidden email]> wrote:

> You can specify the variables in your syntax with delete command
>
> Syntax:
>
> Delete Variables <Var1 name> <Var2 name> <Var3 name> <Var4 name> <Var4
> name>  <Var..n name>.
> exe.
>
> Example:
>
> Delete Variables Var1 Var2 Var3 Var4 Var5.
> exe.
>
>
> Kulvinder
>
> =====================
> 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: Deleting Variables

Keith McCormick
In reply to this post by Hal 9000
Ah ... a macro solution. Agreed. A good way to go. I really want to
get the python to work, though. I am trying to solve problems both
ways to weigh the merits.

Thanks!

On 11/15/07, Hal 9000 <[hidden email]> wrote:

> Right....values, variables....whatever.
>
> Sorry about that....this code (untested), or something very similar,
> ought to do the trick:
>
> ***********************.
> new file.
> data list free /v1_gf v2_bf v3_gf.
> begin data
> 1 2 3
> end data.
>
> set mprint on mexpand on printback on.
> define @D (Z = !charend('/'))
> !do !V !in (!Z)
> !if (!index(!eval(!V), 'gf') > 0) !then
> delete variables !V.
> !ifend
> !doend
> !enddefine.
>
> @D Z = v1_gf v2_bf v3_gf/.
> ***********************************.
>
> On Nov 15, 2007 1:59 AM, Kulvinder Singh <[hidden email]> wrote:
> > You can specify the variables in your syntax with delete command
> >
> > Syntax:
> >
> > Delete Variables <Var1 name> <Var2 name> <Var3 name> <Var4 name> <Var4
> > name>  <Var..n name>.
> > exe.
> >
> > Example:
> >
> > Delete Variables Var1 Var2 Var3 Var4 Var5.
> > exe.
> >
> >
> > Kulvinder
> >
> >
> > =====================
> > 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
Reply | Threaded
Open this post in threaded view
|

Re: Deleting Variables

Peck, Jon
In reply to this post by Keith McCormick
There are several Python ways to do this easily.  One using the basic approach below just collects a list and then deletes at the end if any names meet the criteria.

togo = []
for i in range(NumVar):
  name = spss.GetVariableName(i).lower()
  if name[:3] == "nat":
    togo.append(name)
if togo:
  spss.Submit("DELETE VARIABLE " + " ".join(togo))

Another makes use of the VariableDict object in spssaux.

import spssaux
vardict = spssaux.VariableDict(pattern="nat")
spss.Submit("DELETE VARIABLE " + " ".join(vardict.variables))

The second example makes use of a simple regular expression ... starting with nat... The regular expression approach is much more general since it is easy to specify even quite complicated patterns.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Keith McCormick
Sent: Thursday, November 15, 2007 6:39 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Deleting Variables

Hello,

I found this one interesting. If I am understand it correctly, Hal's
solution deletes DATA that meets the criterion, and Kulvinder's
requires that the name be spelled out in full. Alas, I don't have the
complete answer as there is an error in my code. Perhaps one of the
very good coders on the list can figure it out!

*python_delete_variable .
BEGIN PROGRAM.
import spss
NumVar = spss.GetVariableCount()
for i in range(NumVar):
        name=spss.GetVariableName(i)
        if name.lower()[:3] =="nat":
                spss.Submit("Delete Variable " + name)
END PROGRAM.

The key is that [0:3] or simply [:3] indicates the first three chars
of the variable NAME. Note that [-3:] would be the last three; [-2:]
would be the last two.

The problem is that once the variable is deleted the index changes, so
that it deletes EVERY OTHER instance of a variable that starts with
NAT. I just couldn't fix it.

Although flawed, it shows, I think , the main difference between
syntax and python. Syntax is very good at manipulating data, but
struggles with "meta data".

If anyone can fix the code, please post. I will try to fix it myself.

Keith
www.keithmccormick.com




On 11/15/07, Kulvinder Singh <[hidden email]> wrote:

> You can specify the variables in your syntax with delete command
>
> Syntax:
>
> Delete Variables <Var1 name> <Var2 name> <Var3 name> <Var4 name> <Var4
> name>  <Var..n name>.
> exe.
>
> Example:
>
> Delete Variables Var1 Var2 Var3 Var4 Var5.
> exe.
>
>
> Kulvinder
>
> =====================
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Deleting Variables

Bauer, John H.
In reply to this post by Keith McCormick
Two solutions:

First, you might use reversed() to list the variables from last to first.  Then the change of index doesn't affect the variables in a consequential way:

for i in reversed(range(NumVar)):

Second, you can build a list of just the variables to be deleted.  This is especially nice if you use list comprehensions, which are unique to Python.  They let you write the for loop inside of the list.



*python_delete_variable using reversed().
BEGIN PROGRAM.
import spss
NumVar = spss.GetVariableCount()
for i in reversed(range(NumVar)):
    name=spss.GetVariableName(i)
    if name.lower()[:3] == "nat":
        spss.Submit("Delete Variable " + name)
END PROGRAM.


*python_delete_variable using list.
BEGIN PROGRAM.
import spss
names = []
NumVar = spss.GetVariableCount()
for i in range(NumVar):
    name=spss.GetVariableName(i)
    if name.lower()[:3] == "nat":
        names.append(name)
for name in names:
        spss.Submit("Delete Variable " + name)
END PROGRAM.

*python_delete_variable using list comprehension.
BEGIN PROGRAM.
import spss
names = [spss.GetVariableName(i) for i in range(spss.GetVariableCount())]
names = [name for name in names if name.lower()[:3] == "nat"]
for name in names:
        spss.Submit("Delete Variable " + name)
END PROGRAM.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Keith McCormick
Sent: Thursday, November 15, 2007 7:39 PM
To: [hidden email]
Subject: Re: Deleting Variables

Hello,

I found this one interesting. If I am understand it correctly, Hal's solution deletes DATA that meets the criterion, and Kulvinder's requires that the name be spelled out in full. Alas, I don't have the complete answer as there is an error in my code. Perhaps one of the very good coders on the list can figure it out!

*python_delete_variable .
BEGIN PROGRAM.
import spss
NumVar = spss.GetVariableCount()
for i in range(NumVar):
        name=spss.GetVariableName(i)
        if name.lower()[:3] =="nat":
                spss.Submit("Delete Variable " + name) END PROGRAM.

The key is that [0:3] or simply [:3] indicates the first three chars of the variable NAME. Note that [-3:] would be the last three; [-2:] would be the last two.

The problem is that once the variable is deleted the index changes, so that it deletes EVERY OTHER instance of a variable that starts with NAT. I just couldn't fix it.

Although flawed, it shows, I think , the main difference between syntax and python. Syntax is very good at manipulating data, but struggles with "meta data".

If anyone can fix the code, please post. I will try to fix it myself.

Keith
www.keithmccormick.com




On 11/15/07, Kulvinder Singh <[hidden email]> wrote:

> You can specify the variables in your syntax with delete command
>
> Syntax:
>
> Delete Variables <Var1 name> <Var2 name> <Var3 name> <Var4 name> <Var4
> name>  <Var..n name>.
> exe.
>
> Example:
>
> Delete Variables Var1 Var2 Var3 Var4 Var5.
> exe.
>
>
> Kulvinder
>
> =====================
> 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