Intro Book for SPSS and Python

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

Intro Book for SPSS and Python

Salbod
Good Evening Folks,

                Finally, I got a copy of SPSS 15.0 from the University IT
people. Boy, this new version is loaded with goodies.

How can I learn about Python and SPSS? Is there an introduction book
available?



Thank you,



Stephen Salbod, Pace University, Psychology Dept, NYC
Reply | Threaded
Open this post in threaded view
|

Re: Intro Book for SPSS and Python

Peck, Jon
Go to www.spss.com/devcentral and you will find lots of goodies.  There are some PowerPoints that have good introductory information and other articles on the main page.  But follow the link on the lower right to the 4th edition of the Data Management book.  You can download a pdf free or order a printed copy.

Regards,
Jon Peck
SPSS


-----Original Message-----
From: SPSSX(r) Discussion on behalf of Stephen Salbod
Sent: Tue 5/1/2007 6:38 PM
To: [hidden email]
Subject:      [SPSSX-L] Intro Book for SPSS and Python
 
Good Evening Folks,

                Finally, I got a copy of SPSS 15.0 from the University IT
people. Boy, this new version is loaded with goodies.

How can I learn about Python and SPSS? Is there an introduction book
available?



Thank you,



Stephen Salbod, Pace University, Psychology Dept, NYC
Reply | Threaded
Open this post in threaded view
|

Re: Intro Book for SPSS and Python

Richard Ristow
In reply to this post by Salbod
At 07:38 PM 5/1/2007, Stephen Salbod wrote:

>How can I learn about Python and SPSS? Is there an introduction book
>available?

Jon Peck is absolutely right about "SPSS Programming and Data
Management, 4th Edition". Everyone should have a PDF copy.

Not on SPSS, but for Python, I just fell in love with a suite of
documents from the Python team,  downloadable in various formats from
http://www.python.org/doc/current/download/ . Among other things, it
has complete syntax reference manuals.

>"These archives contain the following documents:
>What's New in Python 2.5
>Python Tutorial
>Python Library Reference  "(keep this under your pillow)"
>Python Reference Manual   "(for language lawyers)"
>Macintosh Library Modules
>Extending and Embedding the Python Interpreter
>Python/C API Reference Manual
>Documenting Python
>Installing Python Modules
>Distributing Python Modules"

Of these, "Python Tutorial",and "Python Library Reference" (very
complete on data and datatypes) are probably the most important.

"Python Reference Manual" describes ALL the syntax. It's not entirely
for the faint of heart; it describes syntax using "rewriting rules":

>"String literals are described by the following lexical definitions:
>
>2.4. Literals 7
>stringliteral   ::= [stringprefix](shortstring | longstring)
>stringprefix    ::= "r" | "u" | "ur" | "R" | "U"
>                   | "UR" | "Ur" | "uR"
>shortstring     ::= "'" shortstringitem* "'"
>                 | '"' shortstringitem* '"'
>longstring      ::= "'''" longstringitem* "'''"
>                   | '"""' longstringitem* '"""'
>shortstringitem ::= shortstringchar | escapeseq
>longstringitem  ::= longstringchar | escapeseq
>shortstringchar ::= <any source character except "\" or newline or the
>quote>
>longstringchar  ::= <any source character except "\">
>escapeseq       ::= "\" <any ASCII character>
Reply | Threaded
Open this post in threaded view
|

Re: Intro Book for SPSS and Python

Peck, Jon
To add a bit to what Richard said,
I would encourage you to grab a beer and sit down in front of your computer and work through chunks of the Python Tutorial from www.python.org.   It is nicely broken up into digestible sections, and you can work its examples and then experiment to see what happens with variations.  That won't teach you anything about the SPSS Python connection, of course, but the DM book will do that.  That book also teaches you simple Python things, mostly by example.

One thing you will want for learning Python -- or for building complex Python programs to run in SPSS -- is a good gui programming editor for Python.  Python comes with IDLE, but there are much better IDEs available, many free.  Personally, I think Pythonwin is the best combination of simplicity and functionality and it is free, so I use it when I teach a course, but I have not tried them all.

For heavy duty Python work, I use Wing IDE Professional, which is not free but not very expensive.  It is more complicated to learn, but it has lots of advanced features.

There are plenty of other good ones, though, both free and commercial.  The important thing is to have one.  It will make life much easier.

HTH,
Jon Peck


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow
Sent: Wednesday, May 02, 2007 10:54 AM
To: [hidden email]
Subject: Re: [SPSSX-L] Intro Book for SPSS and Python

At 07:38 PM 5/1/2007, Stephen Salbod wrote:

>How can I learn about Python and SPSS? Is there an introduction book
>available?

Jon Peck is absolutely right about "SPSS Programming and Data
Management, 4th Edition". Everyone should have a PDF copy.

Not on SPSS, but for Python, I just fell in love with a suite of
documents from the Python team,  downloadable in various formats from
http://www.python.org/doc/current/download/ . Among other things, it
has complete syntax reference manuals.

>"These archives contain the following documents:
>What's New in Python 2.5
>Python Tutorial
>Python Library Reference  "(keep this under your pillow)"
>Python Reference Manual   "(for language lawyers)"
>Macintosh Library Modules
>Extending and Embedding the Python Interpreter
>Python/C API Reference Manual
>Documenting Python
>Installing Python Modules
>Distributing Python Modules"
Reply | Threaded
Open this post in threaded view
|

R v Python?

Gary Rosin
It seems as though many of the stats professionals
are using "R".  How compatible are "R" and Python?
Is there a patch (python procedure) that will let
us run "R" subroutines in SPSS?

---

Gary S. Rosin
Professor of Law
South Texas College of Law
1303 San Jacinto
Houston, TX  77002

<[hidden email]>
713-646-1854
Reply | Threaded
Open this post in threaded view
|

Re: R v Python?

Daniel E WILLIAMS
There are two ways to access R from Python, the "RPy" package
(http://rpy.sourceforge.net/) and R/SPlus - Python Interface
(http://www.omegahat.org/RSPython/).  You might be able to access R from
SPSS (through Python) using one of these libraries.  Many stats
professionals (myself included) who prefer R for statistical analysis
use SPSS, PSPP, or SAS to do their data transformation first, since R
does not handle large datasets well.

Dan Williams
Forecasting, Research and Analysis Office
Department of Human Services
State of Oregon, USA
503 947 5354

>>> "Gary Rosin" <[hidden email]> 5/2/2007 12:40 PM >>>

It seems as though many of the stats professionals
are using "R".  How compatible are "R" and Python?
Is there a patch (python procedure) that will let
us run "R" subroutines in SPSS?

---

Gary S. Rosin
Professor of Law
South Texas College of Law
1303 San Jacinto
Houston, TX  77002

<[hidden email]>
713-646-1854
Reply | Threaded
Open this post in threaded view
|

Do Loop

Edgar F. Johns
Dear Group:

I have a dataset with 64 variables that need to be transformed. The
variables are named SDAC1 TO SDAC64. I want to perform the following
operation for each of the 64 variables:

COMPUTE SDADJ1=0.
DO IF (SDAC1 GE 1).
COMPUTE SDADJ1=1.
END IF.
EXECUTE.

This will create the new variable SDADJn with a 0 or 1.

My question is: how do I set this up in a DO LOOP procedure so I don't have
to write the transformation 64 times for each variable?

Thanks for your help.

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

Beadle, ViAnn
Look at DO REPEAT.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Edgar F. Johns
Sent: Tuesday, May 08, 2007 9:45 AM
To: [hidden email]
Subject: Do Loop

Dear Group:

I have a dataset with 64 variables that need to be transformed. The
variables are named SDAC1 TO SDAC64. I want to perform the following
operation for each of the 64 variables:

COMPUTE SDADJ1=0.
DO IF (SDAC1 GE 1).
COMPUTE SDADJ1=1.
END IF.
EXECUTE.

This will create the new variable SDADJn with a 0 or 1.

My question is: how do I set this up in a DO LOOP procedure so I don't have
to write the transformation 64 times for each variable?

Thanks for your help.

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

Oliver, Richard
In reply to this post by Edgar F. Johns
Use DO REPEAT:

Do repeat x=sdaj1 to sdaj64
   /y=sdac1 to sdac64.
Compute x=0.
If (y > 1) x=1.
End repeat.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Edgar F. Johns
Sent: Tuesday, May 08, 2007 10:45 AM
To: [hidden email]
Subject: Do Loop

Dear Group:

I have a dataset with 64 variables that need to be transformed. The
variables are named SDAC1 TO SDAC64. I want to perform the following
operation for each of the 64 variables:

COMPUTE SDADJ1=0.
DO IF (SDAC1 GE 1).
COMPUTE SDADJ1=1.
END IF.
EXECUTE.

This will create the new variable SDADJn with a 0 or 1.

My question is: how do I set this up in a DO LOOP procedure so I don't have
to write the transformation 64 times for each variable?

Thanks for your help.

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

Edgar F. Johns
In reply to this post by Beadle, ViAnn
Much thanks!

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax

-----Original Message-----
From: Beadle, ViAnn [mailto:[hidden email]]
Sent: Tuesday, May 08, 2007 11:55 AM
To: Edgar F. Johns; [hidden email]
Subject: RE: Do Loop

Look at DO REPEAT.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Edgar F. Johns
Sent: Tuesday, May 08, 2007 9:45 AM
To: [hidden email]
Subject: Do Loop

Dear Group:

I have a dataset with 64 variables that need to be transformed. The
variables are named SDAC1 TO SDAC64. I want to perform the following
operation for each of the 64 variables:

COMPUTE SDADJ1=0.
DO IF (SDAC1 GE 1).
COMPUTE SDADJ1=1.
END IF.
EXECUTE.

This will create the new variable SDADJn with a 0 or 1.

My question is: how do I set this up in a DO LOOP procedure so I don't have
to write the transformation 64 times for each variable?

Thanks for your help.

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

Edgar F. Johns
In reply to this post by Oliver, Richard
Thanks, Richard.

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax

-----Original Message-----
From: Oliver, Richard [mailto:[hidden email]]
Sent: Tuesday, May 08, 2007 11:56 AM
To: Edgar F. Johns; [hidden email]
Subject: RE: Do Loop

Use DO REPEAT:

Do repeat x=sdaj1 to sdaj64
   /y=sdac1 to sdac64.
Compute x=0.
If (y > 1) x=1.
End repeat.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Edgar F. Johns
Sent: Tuesday, May 08, 2007 10:45 AM
To: [hidden email]
Subject: Do Loop

Dear Group:

I have a dataset with 64 variables that need to be transformed. The
variables are named SDAC1 TO SDAC64. I want to perform the following
operation for each of the 64 variables:

COMPUTE SDADJ1=0.
DO IF (SDAC1 GE 1).
COMPUTE SDADJ1=1.
END IF.
EXECUTE.

This will create the new variable SDADJn with a 0 or 1.

My question is: how do I set this up in a DO LOOP procedure so I don't have
to write the transformation 64 times for each variable?

Thanks for your help.

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

rich reeves
In reply to this post by Edgar F. Johns
DO REPEAT is best if you are doing it for a single variable.  But to avoid
multiple loops if you end up using multiple comparisons of a corresponding
enumerated variable in the file you can create vectors
VECTOR VSDAC     = SDAC1 TO SDAC64.
LOOP #K=1 TO 64.
COMPUTE SDADJ1=0.
DO IF (SDAC(#K) GE 1).
COMPUTE SDADJ(#K)=1.
END IF.
END LOOP.
EXE.

On 5/8/07, Edgar F. Johns <[hidden email]> wrote:

>
> Dear Group:
>
> I have a dataset with 64 variables that need to be transformed. The
> variables are named SDAC1 TO SDAC64. I want to perform the following
> operation for each of the 64 variables:
>
> COMPUTE SDADJ1=0.
> DO IF (SDAC1 GE 1).
> COMPUTE SDADJ1=1.
> END IF.
> EXECUTE.
>
> This will create the new variable SDADJn with a 0 or 1.
>
> My question is: how do I set this up in a DO LOOP procedure so I don't
> have
> to write the transformation 64 times for each variable?
>
> Thanks for your help.
>
> Edgar
> ---
> Discover Technologies
> 42020 Koppernick Rd.
> Suite 204
> Canton, MI 48187
> (734) 564-4964
> (734) 468-0800 fax
>
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

Edgar F. Johns
Thanks, Rich. I appreciate your help.

Edgar
---
Discover Technologies
42020 Koppernick Rd.
Suite 204
Canton, MI 48187
(734) 564-4964
(734) 468-0800 fax

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
rich reeves
Sent: Tuesday, May 08, 2007 1:04 PM
To: [hidden email]
Subject: Re: Do Loop

DO REPEAT is best if you are doing it for a single variable.  But to avoid
multiple loops if you end up using multiple comparisons of a corresponding
enumerated variable in the file you can create vectors
VECTOR VSDAC     = SDAC1 TO SDAC64.
LOOP #K=1 TO 64.
COMPUTE SDADJ1=0.
DO IF (SDAC(#K) GE 1).
COMPUTE SDADJ(#K)=1.
END IF.
END LOOP.
EXE.

On 5/8/07, Edgar F. Johns <[hidden email]> wrote:

>
> Dear Group:
>
> I have a dataset with 64 variables that need to be transformed. The
> variables are named SDAC1 TO SDAC64. I want to perform the following
> operation for each of the 64 variables:
>
> COMPUTE SDADJ1=0.
> DO IF (SDAC1 GE 1).
> COMPUTE SDADJ1=1.
> END IF.
> EXECUTE.
>
> This will create the new variable SDADJn with a 0 or 1.
>
> My question is: how do I set this up in a DO LOOP procedure so I don't
> have
> to write the transformation 64 times for each variable?
>
> Thanks for your help.
>
> Edgar
> ---
> Discover Technologies
> 42020 Koppernick Rd.
> Suite 204
> Canton, MI 48187
> (734) 564-4964
> (734) 468-0800 fax
>
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

Richard Ristow
In reply to this post by rich reeves
At 01:03 PM 5/8/2007, rich reeves wrote:

>DO REPEAT is best if you are doing it for a single variable.  But to
>avoid multiple loops if you end up using multiple comparisons of a
>corresponding enumerated variable in the file you can create vectors

I'm not sure quite what you mean, but if you mean running through
several lists of variables in parallel, DO REPEAT works fine:

DO REPEAT GREEK  =    Alpha Beta Gamma
          /ARABIC =    Alif  Ba   Ta
          /ROMAN  =    A     B    C.
.  COMPUTE ROMAN = ARABIC + GREEK.
END REPEAT.

Unlike vectors, the lists in DO REPEAT may be non-contiguous sets of
variables.

Also, DO REPEAT can take lists of constants as well as of variables:

DO REPEAT GREEK    =    Alpha Beta Gamma
          /MULTIPLY =    2     3    5
          /ROMAN    =    A     B    C.
.  COMPUTE ROMAN = MULTIPLY * GREEK.
END REPEAT.

So, why use VECTOR and LOOP, ever? Reasons include,

a.) DO REPEAT can only run through its lists unconditionally. If you
need to stop the loop in the middle, or change the order dynamically,
VECTOR/LOOP is essential. (Code examples from SPSSX-L available on
request.)

b.) You can use XSAVE in a LOOP but not in a DO REPEAT.

c.) For very, very, very long lists (like thousands), DO REPEAT will
expand into lengthy code, since it generates the SPSS statements for
each loop pass.
Reply | Threaded
Open this post in threaded view
|

Re: Do Loop

Art Kendall-2
In reply to this post by Edgar F. Johns
something like this untested syntax should do it
If you want zero, negative numbers. missing values, and system missing
values to be included in the new zero value.
recode sdac1 to sdac64 (1 thru hi =1)(else=0) into sdadj1 to sdadj64.
or if you want to preserve missing values
recode sdac1 to sdac64 (1 thru hi =1)(missing,symis=copy)(else=0) into
sdadj1 to sdadj64.
*define missing values for the new variables.
missing values sdadj1 to sdadj64 (...).

Art Kendall
Social Research Consultants


Edgar F. Johns wrote:

> Dear Group:
>
> I have a dataset with 64 variables that need to be transformed. The
> variables are named SDAC1 TO SDAC64. I want to perform the following
> operation for each of the 64 variables:
>
> COMPUTE SDADJ1=0.
> DO IF (SDAC1 GE 1).
> COMPUTE SDADJ1=1.
> END IF.
> EXECUTE.
>
> This will create the new variable SDADJn with a 0 or 1.
>
> My question is: how do I set this up in a DO LOOP procedure so I don't have
> to write the transformation 64 times for each variable?
>
> Thanks for your help.
>
> Edgar
> ---
> Discover Technologies
> 42020 Koppernick Rd.
> Suite 204
> Canton, MI 48187
> (734) 564-4964
> (734) 468-0800 fax
>
>
>