loop through a list of

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

loop through a list of

Jignesh Sutar
Hi,

I would like to create program which performs similarly to the macro
below.  I would like to adjust it such that it picks up all variables in the
dataset that start with a certain prefix, for example w12m. The dependent
variables start from w12m01 to w12m85, due to the leading zero of the first
9 dependent variables I struggled to create a SPSS macro. Perhaps a python
solution would work better?

Please not also that there are certain variables missing so for example
w12m36 may not exist hence why I want it to search and find all variables of
a specified prefix.

Many thanks for your help.
Jigs



*
http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/LogisticRegressionByMacro.txt
* I want to perform a logistic regression ten times for ten different
variables without having to copy
* and paste the syntax nine times.
* Solution posted by [hidden email] to newsgroup on 2001/05/10.

GET FILE='c:\program files\spss\employee data.sav'.

* Define macro to do the job.
*/////////////////////////.
DEFINE !logist(dv=!TOKENS(1) /iv=!CMDEND)
LOGISTIC REGRESSION VAR=!dv
/METHOD=ENTER !iv
/CRITERIA PIN(.05) POUT(.10) ITERATE(20) CUT(.5) .
!ENDDEFINE.
*/////////////////////////.

* Do logistic regression of gender using salary and educ.
!logist dv=gender iv=salary educ.

* Do logistic regression of minority using salary and jobcat.
!logist dv=gender iv=salary educ.

=====================
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: loop through a list of

ViAnn Beadle
Macros are relatively simple string builders of syntax. They have no
knowledge of the dictionary--that is they have no way of querying what
variables exist. In the past, clever macro writers would actually use SPSS
itself to create the macro. Python, on the other hand, has interfaces into
the dictionary and data so that it can query variable names, types, and such
and even look at the contents of data.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J
Sutar
Sent: Tuesday, September 09, 2008 9:54 AM
To: [hidden email]
Subject: loop through a list of

Hi,

I would like to create program which performs similarly to the macro
below.  I would like to adjust it such that it picks up all variables in the
dataset that start with a certain prefix, for example w12m. The dependent
variables start from w12m01 to w12m85, due to the leading zero of the first
9 dependent variables I struggled to create a SPSS macro. Perhaps a python
solution would work better?

Please not also that there are certain variables missing so for example
w12m36 may not exist hence why I want it to search and find all variables of
a specified prefix.

Many thanks for your help.
Jigs



*
http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/LogisticRegression
ByMacro.txt
* I want to perform a logistic regression ten times for ten different
variables without having to copy
* and paste the syntax nine times.
* Solution posted by [hidden email] to newsgroup on 2001/05/10.

GET FILE='c:\program files\spss\employee data.sav'.

* Define macro to do the job.
*/////////////////////////.
DEFINE !logist(dv=!TOKENS(1) /iv=!CMDEND)
LOGISTIC REGRESSION VAR=!dv
/METHOD=ENTER !iv
/CRITERIA PIN(.05) POUT(.10) ITERATE(20) CUT(.5) .
!ENDDEFINE.
*/////////////////////////.

* Do logistic regression of gender using salary and educ.
!logist dv=gender iv=salary educ.

* Do logistic regression of minority using salary and jobcat.
!logist dv=gender iv=salary educ.

=====================
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: loop through a list of

Peck, Jon
In reply to this post by Jignesh Sutar
If you use the Python spssaux VariableDict object, you can specify a prefix to it and then iterate over the variables in the dictionary.  Something like

begin program.
import spss, spssaux
vardict=spssaux.VariableDict(pattern=r"w12")
for v in vardict:
   spss.Submit("LOGISTIC REGRESSION VARIABLES %s /METHOD ..." % v)
end program.

HTH

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar
Sent: Tuesday, September 09, 2008 9:54 AM
To: [hidden email]
Subject: [SPSSX-L] loop through a list of

Hi,

I would like to create program which performs similarly to the macro
below.  I would like to adjust it such that it picks up all variables in the
dataset that start with a certain prefix, for example w12m. The dependent
variables start from w12m01 to w12m85, due to the leading zero of the first
9 dependent variables I struggled to create a SPSS macro. Perhaps a python
solution would work better?

Please not also that there are certain variables missing so for example
w12m36 may not exist hence why I want it to search and find all variables of
a specified prefix.

Many thanks for your help.
Jigs



*
http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/LogisticRegressionByMacro.txt
* I want to perform a logistic regression ten times for ten different
variables without having to copy
* and paste the syntax nine times.
* Solution posted by [hidden email] to newsgroup on 2001/05/10.

GET FILE='c:\program files\spss\employee data.sav'.

* Define macro to do the job.
*/////////////////////////.
DEFINE !logist(dv=!TOKENS(1) /iv=!CMDEND)
LOGISTIC REGRESSION VAR=!dv
/METHOD=ENTER !iv
/CRITERIA PIN(.05) POUT(.10) ITERATE(20) CUT(.5) .
!ENDDEFINE.
*/////////////////////////.

* Do logistic regression of gender using salary and educ.
!logist dv=gender iv=salary educ.

* Do logistic regression of minority using salary and jobcat.
!logist dv=gender iv=salary educ.

=====================
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: loop through a list of

Jignesh Sutar
Thanks Jon,

I now have the following program (see below) but as it stands it enters the
variable name in the TITLE spss command. I would like to change this so that
it enters the variable label?



BEGIN PROGRAM.
import spss, spssaux
vardict=spssaux.VariableDict(pattern=r"w12m")
for v in vardict:
 spss.Submit("""
TITLE %s

LOGISTIC REGRESSION VARIABLES  %s
  /METHOD = FSTEP(LR) age_15_24 age_25_34 age_35_44 age_45_54 age_55_64
age_65x soc_a soc_b soc_c1 soc_c2 soc_d soc_e
  /SAVE = PRED(P_%s)
  /PRINT = SUMMARY
  /CRITERIA = PIN(.05) POUT(.10) ITERATE(20) CUT(.5) .
""" % (v,v,v))
END PROGRAM.

Many Thanks

Jigs
2008/9/9 Peck, Jon <[hidden email]>

> If you use the Python spssaux VariableDict object, you can specify a prefix
> to it and then iterate over the variables in the dictionary.  Something like
>
> begin program.
> import spss, spssaux
> vardict=spssaux.VariableDict(pattern=r"w12")
> for v in vardict:
>   spss.Submit("LOGISTIC REGRESSION VARIABLES %s /METHOD ..." % v)
> end program.
>
> HTH
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J
> Sutar
> Sent: Tuesday, September 09, 2008 9:54 AM
> To: [hidden email]
>  Subject: [SPSSX-L] loop through a list of
>
> Hi,
>
> I would like to create program which performs similarly to the macro
> below.  I would like to adjust it such that it picks up all variables in
> the
> dataset that start with a certain prefix, for example w12m. The dependent
> variables start from w12m01 to w12m85, due to the leading zero of the first
> 9 dependent variables I struggled to create a SPSS macro. Perhaps a python
> solution would work better?
>
> Please not also that there are certain variables missing so for example
> w12m36 may not exist hence why I want it to search and find all variables
> of
> a specified prefix.
>
> Many thanks for your help.
> Jigs
>
>
>
> *
>
> http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/LogisticRegressionByMacro.txt
> * I want to perform a logistic regression ten times for ten different
> variables without having to copy
> * and paste the syntax nine times.
> * Solution posted by [hidden email] to newsgroup on 2001/05/10.
>
> GET FILE='c:\program files\spss\employee data.sav'.
>
> * Define macro to do the job.
> */////////////////////////.
> DEFINE !logist(dv=!TOKENS(1) /iv=!CMDEND)
> LOGISTIC REGRESSION VAR=!dv
> /METHOD=ENTER !iv
> /CRITERIA PIN(.05) POUT(.10) ITERATE(20) CUT(.5) .
> !ENDDEFINE.
> */////////////////////////.
>
> * Do logistic regression of gender using salary and educ.
> !logist dv=gender iv=salary educ.
>
> * Do logistic regression of minority using salary and jobcat.
> !logist dv=gender iv=salary educ.
>
>  =====================
> 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: loop through a list of

Peck, Jon
See below.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar
Sent: Wednesday, September 10, 2008 10:19 AM
To: [hidden email]
Subject: Re: [SPSSX-L] loop through a list of

Thanks Jon,

I now have the following program (see below) but as it stands it enters the
variable name in the TITLE spss command. I would like to change this so that
it enters the variable label?



BEGIN PROGRAM.
import spss, spssaux
vardict=spssaux.VariableDict(pattern=r"w12m")
for v in vardict:
 spss.Submit("""
TITLE %s

LOGISTIC REGRESSION VARIABLES  %s
  /METHOD = FSTEP(LR) age_15_24 age_25_34 age_35_44 age_45_54 age_55_64
age_65x soc_a soc_b soc_c1 soc_c2 soc_d soc_e
  /SAVE = PRED(P_%s)
  /PRINT = SUMMARY
  /CRITERIA = PIN(.05) POUT(.10) ITERATE(20) CUT(.5) .
""" % (v,v,v))
END PROGRAM.

[>>>Peck, Jon]
v is a Variable object, and it has all the properties of a variable.  So all you have to do is to change the first v in (v,v,v), which is the one that applies to the TITLE line, to
v.VariableLabel

Regards,
Jon


Many Thanks

Jigs
2008/9/9 Peck, Jon <[hidden email]>

> If you use the Python spssaux VariableDict object, you can specify a prefix
> to it and then iterate over the variables in the dictionary.  Something like
>
> begin program.
> import spss, spssaux
> vardict=spssaux.VariableDict(pattern=r"w12")
> for v in vardict:
>   spss.Submit("LOGISTIC REGRESSION VARIABLES %s /METHOD ..." % v)
> end program.
>
> HTH
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J
> Sutar
> Sent: Tuesday, September 09, 2008 9:54 AM
> To: [hidden email]
>  Subject: [SPSSX-L] loop through a list of
>
> Hi,
>
> I would like to create program which performs similarly to the macro
> below.  I would like to adjust it such that it picks up all variables in
> the
> dataset that start with a certain prefix, for example w12m. The dependent
> variables start from w12m01 to w12m85, due to the leading zero of the first
> 9 dependent variables I struggled to create a SPSS macro. Perhaps a python
> solution would work better?
>
> Please not also that there are certain variables missing so for example
> w12m36 may not exist hence why I want it to search and find all variables
> of
> a specified prefix.
>
> Many thanks for your help.
> Jigs
>
>
>
> *
>
> http://www.spsstools.net/Syntax/RegressionRepeatedMeasure/LogisticRegressionByMacro.txt
> * I want to perform a logistic regression ten times for ten different
> variables without having to copy
> * and paste the syntax nine times.
> * Solution posted by [hidden email] to newsgroup on 2001/05/10.
>
> GET FILE='c:\program files\spss\employee data.sav'.
>
> * Define macro to do the job.
> */////////////////////////.
> DEFINE !logist(dv=!TOKENS(1) /iv=!CMDEND)
> LOGISTIC REGRESSION VAR=!dv
> /METHOD=ENTER !iv
> /CRITERIA PIN(.05) POUT(.10) ITERATE(20) CUT(.5) .
> !ENDDEFINE.
> */////////////////////////.
>
> * Do logistic regression of gender using salary and educ.
> !logist dv=gender iv=salary educ.
>
> * Do logistic regression of minority using salary and jobcat.
> !logist dv=gender iv=salary educ.
>
>  =====================
> 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