Ctables, Python, tables.py (merging stat testing)

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

Ctables, Python, tables.py (merging stat testing)

Tim AT Home
Okay, still not able to solve all my issues - hoping someone out there has
some examples


I AM able to merge /COMPARETEST TYPE=PROP tables


I have had NO success in merging /COMPARETEST TYPE=MEAN tables

AND

I have had NO success obviously in merging tables with BOTH /COMPARETEST
TYPE=PROP
AND /COMPARETEST TYPE=MEAN (where SPSS generates 3 tables)

Lastly,

My general setup uses

Define!

ctables (anywhere from 1 TO 500+ times)

!Enddefine

with macro variables for things like column width, title, banner (the
columns for those not in Market Research), etc.
What I find though - is that I CANNOT add the python language block to merge
tables within Define/EndDefine.  This
really puts a crimp on my productivity - where the soln I see at this point
is to not use Define/EndDefine.
This will cause me to need to replicate each 'tables' file for each specific
run - which has totalled more than 100
in cases - and would require modication of all these files each time a
change is made in stubs (row variables
for those not in Market Research) which can occur somewhat frequently over
the course of a job.  Any
suggestions???


Thanks!

Tim



****************************

Notice: This e-mail and any attachments may contain confidential and
privileged information.  If you are not the intended recipient, please
notify the sender immediately by return e-mail, do not use the information,
delete this e-mail and destroy any copies.  Any dissemination or use of this
information by a person other than the intended recipient is unauthorized
and may be illegal.  Email transmissions cannot be guaranteed to be secure
or error free. The sender therefore does not accept any liability for errors
or omissions in the contents of this message that arise as a result of email
transmissions.

=====================
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: Ctables, Python, tables.py (merging stat testing)

Peck, Jon
It is hard to diagnose the problem without the exact details.  Means tests should work the same as proportion tests, but, of course, you would need to define the join point differently, since the default join point is based on COUNT.

As for the macro question, the cleanest way to use the Python stuff is to replace the macro portion with Python code.  If you have a specific example, I can explain this more precisely, but the Python code will almost always be simpler and easier to read (and write).  If you are just defining a macro to hold a stock block of syntax, it can be replaced by a Python string.  If you are running a whole batch of syntax in the macro that should be factored out from the rest, you can make it a separate function or module and just call it as needed.

If you just need to use a macro in your Ctables syntax, that works just as well with the Python Submit function as it does in regular syntax.

What you cannot do is to put your Python code inside a macro definition.  That would raise a whole host of problems of interpretation and expansion.  If, though, you have a big block of syntax that you want to run inside your Python code, using Submit with triple-quoted strings allows you to run that code virtually unchanged inside your Python program.

Regards,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Tim Hennigar
Sent: Tuesday, October 23, 2007 2:50 PM
To: [hidden email]
Subject: [SPSSX-L] Ctables, Python, tables.py (merging stat testing)

Okay, still not able to solve all my issues - hoping someone out there has
some examples


I AM able to merge /COMPARETEST TYPE=PROP tables


I have had NO success in merging /COMPARETEST TYPE=MEAN tables

AND

I have had NO success obviously in merging tables with BOTH /COMPARETEST
TYPE=PROP
AND /COMPARETEST TYPE=MEAN (where SPSS generates 3 tables)

Lastly,

My general setup uses

Define!

ctables (anywhere from 1 TO 500+ times)

!Enddefine

with macro variables for things like column width, title, banner (the
columns for those not in Market Research), etc.
What I find though - is that I CANNOT add the python language block to merge
tables within Define/EndDefine.  This
really puts a crimp on my productivity - where the soln I see at this point
is to not use Define/EndDefine.
This will cause me to need to replicate each 'tables' file for each specific
run - which has totalled more than 100
in cases - and would require modication of all these files each time a
change is made in stubs (row variables
for those not in Market Research) which can occur somewhat frequently over
the course of a job.  Any
suggestions???


Thanks!

Tim



****************************

Notice: This e-mail and any attachments may contain confidential and
privileged information.  If you are not the intended recipient, please
notify the sender immediately by return e-mail, do not use the information,
delete this e-mail and destroy any copies.  Any dissemination or use of this
information by a person other than the intended recipient is unauthorized
and may be illegal.  Email transmissions cannot be guaranteed to be secure
or error free. The sender therefore does not accept any liability for errors
or omissions in the contents of this message that arise as a result of email
transmissions.

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

Stacking Data

John Fiedler
In market research surveys, I frequently have datasets in which respondents evaluate a number of products on several ratings scales. In some cases a respondent might rate two dozen products on a dozen or more attributes. Analysis is facilitated by stacking the data. I've always done this by reading the source data file repeatedly and writing out files containing the data for each product and adding the resulting files.

An example is shown below. The process works just fine. However with vary large data sets (35,000 respondents, >3,000 products) the process becomes very cumbersome and is open to error.

Does anyone know a more efficient way to "stack data"?

JOHN

* Stacking Data Exercise.

DATA LIST FREE

/respnum proda rata1 TO rata4 prodb ratb1 TO ratb4 prodc ratc1 TO ratc4.

BEGIN DATA.

1001 11 1 3 4 5   14 5 3 2 4   14 4 3 2 5

1002 18 2 2 2 3   16 4 2 1 4   17 2 1 5 3

1003 21 4 5 3 5   23 4 4 4 1   25 1 3 4 5

1004 12 1 1 4 1   19 3 3 3 4   10 3 5 2 1

END DATA.

 

SAVE OUTFILE = "c:\windows\temp\temp.sys".

 

GET

  FILE    = "c:\windows\temp\temp.sys"

 /KEEP    = respnum proda rata1 TO rata4

 /RENAME  = (proda rata1 TO rata4 = prod rat1 TO rat4).

SAVE

  OUTFILE =  "c:\windows\temp\temp_prda.sys".

 

GET

  FILE    = "c:\windows\temp\temp.sys"

 /KEEP    = respnum prodb ratb1 TO ratb4

 /RENAME  = (prodb ratb1 TO ratb4 = prod rat1 TO rat4).

SAVE

  OUTFILE =  "c:\windows\temp\temp_prdb.sys".

 

GET

  FILE    = "c:\windows\temp\temp.sys"

 /KEEP    = respnum prodc ratc1 TO ratc4

 /RENAME  = (prodc ratc1 TO ratc4 = prod rat1 TO rat4).

SAVE

  OUTFILE =  "c:\windows\temp\temp_prdc.sys".

 

ADD FILES

  FILE =  "c:\windows\temp\temp_prda.sys"

 /FILE =  "c:\windows\temp\temp_prdb.sys"

 /FILE =  "c:\windows\temp\temp_prdc.sys".

 

SORT CASES BY respnum prod.

 

LIST VARS

 respnum prod rat1 TO rat4.

====================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: Stacking Data

Marks, Jim
 Does VARSTOCASES do what you want?


* Stacking Data Exercise.

DATA LIST FREE
  /respnum proda rata1 TO rata4 prodb ratb1 TO ratb4 prodc ratc1 TO
ratc4.

BEGIN DATA
1001 11 1 3 4 5   14 5 3 2 4   14 4 3 2 5
1002 18 2 2 2 3   16 4 2 1 4   17 2 1 5 3
1003 21 4 5 3 5   23 4 4 4 1   25 1 3 4 5
1004 12 1 1 4 1   19 3 3 3 4   10 3 5 2 1
END DATA.

VARSTOCASES
   /MAKE prod FROM proda prodb prodc
  /make rat1 from rata1 ratb1 ratc1
 /make rat2 from rata2 ratb2 ratc2
  /make rat3 from rata3 ratb3 ratc3
 /make rat4 from rata4 ratb4 ratc4
 /KEEP =  respnum
 /NULL = KEEP.


this creates a new working data set with 12 cases (3 cases for each id)
and 5 variables:
respnum =       respondent id
prod            =       product id (was proda, prodb, prodc)
rat1            =       first rating
rat2            =       second rating
rat3            =       third rating

--jim


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
John Fiedler
Sent: Monday, October 29, 2007 9:55 AM
To: [hidden email]
Subject: Stacking Data

In market research surveys, I frequently have datasets in which
respondents evaluate a number of products on several ratings scales. In
some cases a respondent might rate two dozen products on a dozen or more
attributes. Analysis is facilitated by stacking the data. I've always
done this by reading the source data file repeatedly and writing out
files containing the data for each product and adding the resulting
files.

An example is shown below. The process works just fine. However with
vary large data sets (35,000 respondents, >3,000 products) the process
becomes very cumbersome and is open to error.

Does anyone know a more efficient way to "stack data"?

JOHN

* Stacking Data Exercise.

DATA LIST FREE

/respnum proda rata1 TO rata4 prodb ratb1 TO ratb4 prodc ratc1 TO ratc4.

BEGIN DATA.

1001 11 1 3 4 5   14 5 3 2 4   14 4 3 2 5

1002 18 2 2 2 3   16 4 2 1 4   17 2 1 5 3

1003 21 4 5 3 5   23 4 4 4 1   25 1 3 4 5

1004 12 1 1 4 1   19 3 3 3 4   10 3 5 2 1

END DATA.



SAVE OUTFILE = "c:\windows\temp\temp.sys".



GET

  FILE    = "c:\windows\temp\temp.sys"

 /KEEP    = respnum proda rata1 TO rata4

 /RENAME  = (proda rata1 TO rata4 = prod rat1 TO rat4).

SAVE

  OUTFILE =  "c:\windows\temp\temp_prda.sys".



GET

  FILE    = "c:\windows\temp\temp.sys"

 /KEEP    = respnum prodb ratb1 TO ratb4

 /RENAME  = (prodb ratb1 TO ratb4 = prod rat1 TO rat4).

SAVE

  OUTFILE =  "c:\windows\temp\temp_prdb.sys".



GET

  FILE    = "c:\windows\temp\temp.sys"

 /KEEP    = respnum prodc ratc1 TO ratc4

 /RENAME  = (prodc ratc1 TO ratc4 = prod rat1 TO rat4).

SAVE

  OUTFILE =  "c:\windows\temp\temp_prdc.sys".



ADD FILES

  FILE =  "c:\windows\temp\temp_prda.sys"

 /FILE =  "c:\windows\temp\temp_prdb.sys"

 /FILE =  "c:\windows\temp\temp_prdc.sys".



SORT CASES BY respnum prod.



LIST VARS

 respnum prod rat1 TO rat4.

=======
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: Stacking Data

John Fiedler
Yes, perfectly.
I missed VARSTOCASES when I upgraded from version 6.1.4 to version 14!
JOHN

----- Original Message -----
From: "Marks, Jim" <[hidden email]>
To: <[hidden email]>
Sent: Monday, October 29, 2007 12:32 PM
Subject: Re: Stacking Data


> Does VARSTOCASES do what you want?
>
>
> * Stacking Data Exercise.
>
> DATA LIST FREE
>  /respnum proda rata1 TO rata4 prodb ratb1 TO ratb4 prodc ratc1 TO
> ratc4.
>
> BEGIN DATA
> 1001 11 1 3 4 5   14 5 3 2 4   14 4 3 2 5
> 1002 18 2 2 2 3   16 4 2 1 4   17 2 1 5 3
> 1003 21 4 5 3 5   23 4 4 4 1   25 1 3 4 5
> 1004 12 1 1 4 1   19 3 3 3 4   10 3 5 2 1
> END DATA.
>
> VARSTOCASES
>   /MAKE prod FROM proda prodb prodc
>  /make rat1 from rata1 ratb1 ratc1
> /make rat2 from rata2 ratb2 ratc2
>  /make rat3 from rata3 ratb3 ratc3
> /make rat4 from rata4 ratb4 ratc4
> /KEEP =  respnum
> /NULL = KEEP.
>
>
> this creates a new working data set with 12 cases (3 cases for each id)
> and 5 variables:
> respnum =       respondent id
> prod            =       product id (was proda, prodb, prodc)
> rat1            =       first rating
> rat2            =       second rating
> rat3            =       third rating
>
> --jim
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> John Fiedler
> Sent: Monday, October 29, 2007 9:55 AM
> To: [hidden email]
> Subject: Stacking Data
>
> In market research surveys, I frequently have datasets in which
> respondents evaluate a number of products on several ratings scales. In
> some cases a respondent might rate two dozen products on a dozen or more
> attributes. Analysis is facilitated by stacking the data. I've always
> done this by reading the source data file repeatedly and writing out
> files containing the data for each product and adding the resulting
> files.
>
> An example is shown below. The process works just fine. However with
> vary large data sets (35,000 respondents, >3,000 products) the process
> becomes very cumbersome and is open to error.
>
> Does anyone know a more efficient way to "stack data"?
>
> JOHN
>
> * Stacking Data Exercise.
>
> DATA LIST FREE
>
> /respnum proda rata1 TO rata4 prodb ratb1 TO ratb4 prodc ratc1 TO ratc4.
>
> BEGIN DATA.
>
> 1001 11 1 3 4 5   14 5 3 2 4   14 4 3 2 5
>
> 1002 18 2 2 2 3   16 4 2 1 4   17 2 1 5 3
>
> 1003 21 4 5 3 5   23 4 4 4 1   25 1 3 4 5
>
> 1004 12 1 1 4 1   19 3 3 3 4   10 3 5 2 1
>
> END DATA.
>
>
>
> SAVE OUTFILE = "c:\windows\temp\temp.sys".
>
>
>
> GET
>
>  FILE    = "c:\windows\temp\temp.sys"
>
> /KEEP    = respnum proda rata1 TO rata4
>
> /RENAME  = (proda rata1 TO rata4 = prod rat1 TO rat4).
>
> SAVE
>
>  OUTFILE =  "c:\windows\temp\temp_prda.sys".
>
>
>
> GET
>
>  FILE    = "c:\windows\temp\temp.sys"
>
> /KEEP    = respnum prodb ratb1 TO ratb4
>
> /RENAME  = (prodb ratb1 TO ratb4 = prod rat1 TO rat4).
>
> SAVE
>
>  OUTFILE =  "c:\windows\temp\temp_prdb.sys".
>
>
>
> GET
>
>  FILE    = "c:\windows\temp\temp.sys"
>
> /KEEP    = respnum prodc ratc1 TO ratc4
>
> /RENAME  = (prodc ratc1 TO ratc4 = prod rat1 TO rat4).
>
> SAVE
>
>  OUTFILE =  "c:\windows\temp\temp_prdc.sys".
>
>
>
> ADD FILES
>
>  FILE =  "c:\windows\temp\temp_prda.sys"
>
> /FILE =  "c:\windows\temp\temp_prdb.sys"
>
> /FILE =  "c:\windows\temp\temp_prdc.sys".
>
>
>
> SORT CASES BY respnum prod.
>
>
>
> LIST VARS
>
> respnum prod rat1 TO rat4.
>
> =======
> 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