Problems with CTABLES output

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

Problems with CTABLES output

John F Hall

I am reproducing some analysis from Babbie et al 2019, but using syntax rather than the GUI

(Which tells me I can’t nest scale variables, but they are all nominal).

 

The following syntax gets halfway to what I want.

 

 

CTABLES

/table postlife > vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

895

2 Did not vote

39.3

60.7

351

3 Ineligible

36.4

63.6

77

Total

40.8

59.2

1323

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

180

2 Did not vote

50.5

49.5

93

3 Ineligible

52.2

47.8

23

Total

64.5

35.5

296

Total

VOTE12 Did R vote in 2012 election

1 Voted

47.1

52.9

1075

2 Did not vote

41.7

58.3

444

3 Ineligible

40.0

60.0

100

Total

45.2

54.8

1619

 

Bruce Weaver’s original 2016 macro from Nabble thread “Making SPSS better”

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

27.8%

38.7%

100.0%

374

521

895

2 Did not vote

24.3%

37.6%

100.0%

138

213

351

3 Ineligible

20.3%

35.5%

100.0%

28

49

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

44.6%

16.2%

100.0%

132

48

180

2 Did not vote

30.3%

29.7%

100.0%

47

46

93

3 Ineligible

30.8%

28.2%

100.0%

12

11

23

NOTE:  Cells show ROWPCT and COUNT

 

 

Bruce Weaver’s macro modified

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c]

[rowpct.count f5.1 "%" totals [count "n= 100%"]] 

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

 

 

 

895

2 Did not vote

39.3

60.7

 

 

 

351

3 Ineligible

36.4

63.6

 

 

 

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

 

 

 

180

2 Did not vote

50.5

49.5

 

 

 

93

3 Ineligible

52.2

47.8

 

 

 

23

NOTE:  Cells show ROWPCT and COUNT

 

I can’t get the totals on the same line as the %%

The following syntax (from Weaver macro modified again)  puts 100% where I want the row total Ns.

 

 

CTABLES

/table postlife by vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason:   1 YES 

 

VOTE12 Did R vote in 2012 election

1 Voted

2 Did not vote

3 Ineligible

Total

%

%

%

%

POSTLIFE Belief in life after death

1 YES

69.3

25.6

5.2

100.0

2 NO

69.1

24.6

6.3

100.0

Total

69.2

25.3

5.5

100.0

 

Short of doing:

 

TEMP.

SELECT IF vote12 = 1.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

41.8

58.2

895

2 NO

73.3

26.7

180

Total

47.1

52.9

1075

 

 

TEMP.

SELECT IF vote12 = 2.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

39.3

60.7

351

2 NO

50.5

49.5

93

Total

41.7

58.3

444

 

Is there any way I can modify the macro to do this?   

 

I tried:

 

SORT CASES by vote12.

SPLIT FILE by vote12.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

But got:

 

Warnings

CATEGORIES: Variable vote12. The variable list specifies a scale variable or an undefined variable. The variable will be ignored.

The SPLIT FILE option LAYERED is ignored in Custom tables. To compare groups, use the split variables as the outermost row variables in the table.

 

Vote12 is Nominal, so what is SPSS playing at?  I went via GUI just to get the syntax from PASTE, but have been running syntax direct since.  Or is it because I’m not wearing a mask?

 

Thanks in advance for help.

 

John F Hall MA (Cantab) Dip Ed (Dunelm)

IBM-SPSS Academic Author 9900074

 

Email: [hidden email]

Website: Journeys in Survey Research

Course: Survey Analysis Workshop (SPSS)

 

===================== 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: Problems with CTABLES output

Jon Peck
Something like this will do it.
CTABLES
  /TABLE gender [C] > jobcat [C] BY minority [C][ROWPCT.COUNT TOTALS[COUNT]]
  /CATEGORIES VARIABLES=minority TOTAL=YES.

When you specify SLABELS POSITION=ROW
and there are different statistics for the totals (or other column variables), CTABLES puts each statistic type on a separate row so that they can be labelled correctly even though in this case you are suppressing the labels.

And, BTW, the gui is correct: you can't nest a scale variable under a scale variable - it wouldn't make sense.  But in syntax you can override the variable's measurement level by using [C].  You can do that in the gui by right clicking the variable in the Variables control before dragging it and setting the level, temporarily, to a categorical value.

On Tue, Apr 28, 2020 at 4:53 AM Joihn F Hall <[hidden email]> wrote:

I am reproducing some analysis from Babbie et al 2019, but using syntax rather than the GUI

(Which tells me I can’t nest scale variables, but they are all nominal).

 

The following syntax gets halfway to what I want.

 

 

CTABLES

/table postlife > vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

895

2 Did not vote

39.3

60.7

351

3 Ineligible

36.4

63.6

77

Total

40.8

59.2

1323

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

180

2 Did not vote

50.5

49.5

93

3 Ineligible

52.2

47.8

23

Total

64.5

35.5

296

Total

VOTE12 Did R vote in 2012 election

1 Voted

47.1

52.9

1075

2 Did not vote

41.7

58.3

444

3 Ineligible

40.0

60.0

100

Total

45.2

54.8

1619

 

Bruce Weaver’s original 2016 macro from Nabble thread “Making SPSS better”

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

27.8%

38.7%

100.0%

374

521

895

2 Did not vote

24.3%

37.6%

100.0%

138

213

351

3 Ineligible

20.3%

35.5%

100.0%

28

49

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

44.6%

16.2%

100.0%

132

48

180

2 Did not vote

30.3%

29.7%

100.0%

47

46

93

3 Ineligible

30.8%

28.2%

100.0%

12

11

23

NOTE:  Cells show ROWPCT and COUNT

 

 

Bruce Weaver’s macro modified

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c]

[rowpct.count f5.1 "%" totals [count "n= 100%"]] 

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

 

 

 

895

2 Did not vote

39.3

60.7

 

 

 

351

3 Ineligible

36.4

63.6

 

 

 

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

 

 

 

180

2 Did not vote

50.5

49.5

 

 

 

93

3 Ineligible

52.2

47.8

 

 

 

23

NOTE:  Cells show ROWPCT and COUNT

 

I can’t get the totals on the same line as the %%

The following syntax (from Weaver macro modified again)  puts 100% where I want the row total Ns.

 

 

CTABLES

/table postlife by vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason:   1 YES 

 

VOTE12 Did R vote in 2012 election

1 Voted

2 Did not vote

3 Ineligible

Total

%

%

%

%

POSTLIFE Belief in life after death

1 YES

69.3

25.6

5.2

100.0

2 NO

69.1

24.6

6.3

100.0

Total

69.2

25.3

5.5

100.0

 

Short of doing:

 

TEMP.

SELECT IF vote12 = 1.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

41.8

58.2

895

2 NO

73.3

26.7

180

Total

47.1

52.9

1075

 

 

TEMP.

SELECT IF vote12 = 2.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

39.3

60.7

351

2 NO

50.5

49.5

93

Total

41.7

58.3

444

 

Is there any way I can modify the macro to do this?   

 

I tried:

 

SORT CASES by vote12.

SPLIT FILE by vote12.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

But got:

 

Warnings

CATEGORIES: Variable vote12. The variable list specifies a scale variable or an undefined variable. The variable will be ignored.

The SPLIT FILE option LAYERED is ignored in Custom tables. To compare groups, use the split variables as the outermost row variables in the table.

 

Vote12 is Nominal, so what is SPSS playing at?  I went via GUI just to get the syntax from PASTE, but have been running syntax direct since.  Or is it because I’m not wearing a mask?

 

Thanks in advance for help.

 

John F Hall MA (Cantab) Dip Ed (Dunelm)

IBM-SPSS Academic Author 9900074

 

Email: [hidden email]

Website: Journeys in Survey Research

Course: Survey Analysis Workshop (SPSS)

 

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


--
Jon K Peck
[hidden email]

===================== 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: Problems with CTABLES output

John F Hall

That works fine, but it doesn’t explain why SPSS treats vote12 as scale when it’s nominal.  Will now attempt to modify Bruce’s macro again.

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Jon Peck
Sent: 28 April 2020 15:15
To: [hidden email]
Subject: Re: Problems with CTABLES output

 

Something like this will do it.

CTABLES
  /TABLE gender [C] > jobcat [C] BY minority [C][ROWPCT.COUNT TOTALS[COUNT]]
  /CATEGORIES VARIABLES=minority TOTAL=YES.

 

When you specify SLABELS POSITION=ROW

and there are different statistics for the totals (or other column variables), CTABLES puts each statistic type on a separate row so that they can be labelled correctly even though in this case you are suppressing the labels.

 

And, BTW, the gui is correct: you can't nest a scale variable under a scale variable - it wouldn't make sense.  But in syntax you can override the variable's measurement level by using [C].  You can do that in the gui by right clicking the variable in the Variables control before dragging it and setting the level, temporarily, to a categorical value.

 

On Tue, Apr 28, 2020 at 4:53 AM Joihn F Hall <[hidden email]> wrote:

I am reproducing some analysis from Babbie et al 2019, but using syntax rather than the GUI

(Which tells me I can’t nest scale variables, but they are all nominal).

 

The following syntax gets halfway to what I want.

 

 

CTABLES

/table postlife > vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

895

2 Did not vote

39.3

60.7

351

3 Ineligible

36.4

63.6

77

Total

40.8

59.2

1323

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

180

2 Did not vote

50.5

49.5

93

3 Ineligible

52.2

47.8

23

Total

64.5

35.5

296

Total

VOTE12 Did R vote in 2012 election

1 Voted

47.1

52.9

1075

2 Did not vote

41.7

58.3

444

3 Ineligible

40.0

60.0

100

Total

45.2

54.8

1619

 

Bruce Weaver’s original 2016 macro from Nabble thread “Making SPSS better”

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

27.8%

38.7%

100.0%

374

521

895

2 Did not vote

24.3%

37.6%

100.0%

138

213

351

3 Ineligible

20.3%

35.5%

100.0%

28

49

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

44.6%

16.2%

100.0%

132

48

180

2 Did not vote

30.3%

29.7%

100.0%

47

46

93

3 Ineligible

30.8%

28.2%

100.0%

12

11

23

NOTE:  Cells show ROWPCT and COUNT

 

 

Bruce Weaver’s macro modified

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c]

[rowpct.count f5.1 "%" totals [count "n= 100%"]] 

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

 

 

 

895

2 Did not vote

39.3

60.7

 

 

 

351

3 Ineligible

36.4

63.6

 

 

 

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

 

 

 

180

2 Did not vote

50.5

49.5

 

 

 

93

3 Ineligible

52.2

47.8

 

 

 

23

NOTE:  Cells show ROWPCT and COUNT

 

I can’t get the totals on the same line as the %%

The following syntax (from Weaver macro modified again)  puts 100% where I want the row total Ns.

 

 

CTABLES

/table postlife by vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason:   1 YES 

 

VOTE12 Did R vote in 2012 election

1 Voted

2 Did not vote

3 Ineligible

Total

%

%

%

%

POSTLIFE Belief in life after death

1 YES

69.3

25.6

5.2

100.0

2 NO

69.1

24.6

6.3

100.0

Total

69.2

25.3

5.5

100.0

 

Short of doing:

 

TEMP.

SELECT IF vote12 = 1.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

41.8

58.2

895

2 NO

73.3

26.7

180

Total

47.1

52.9

1075

 

 

TEMP.

SELECT IF vote12 = 2.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

39.3

60.7

351

2 NO

50.5

49.5

93

Total

41.7

58.3

444

 

Is there any way I can modify the macro to do this?   

 

I tried:

 

SORT CASES by vote12.

SPLIT FILE by vote12.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

But got:

 

Warnings

CATEGORIES: Variable vote12. The variable list specifies a scale variable or an undefined variable. The variable will be ignored.

The SPLIT FILE option LAYERED is ignored in Custom tables. To compare groups, use the split variables as the outermost row variables in the table.

 

Vote12 is Nominal, so what is SPSS playing at?  I went via GUI just to get the syntax from PASTE, but have been running syntax direct since.  Or is it because I’m not wearing a mask?

 

Thanks in advance for help.

 

John F Hall MA (Cantab) Dip Ed (Dunelm)

IBM-SPSS Academic Author 9900074

 

Email: [hidden email]

Website: Journeys in Survey Research

Course: Survey Analysis Workshop (SPSS)

 

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


 

--

Jon K Peck
[hidden email]

===================== 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: Problems with CTABLES output

Bruce Weaver
Administrator
In reply to this post by John F Hall
For the record, I had no recollection of writing a macro called ELABORATE.
It turns out I didn't.  I wrote a macro called CrossBreak.  John
subsequently tweaked it and renamed it ELABORATE.  

http://spssx-discussion.1045642.n5.nabble.com/Making-SPSS-better-tp5732642p5732775.html
http://spssx-discussion.1045642.n5.nabble.com/Making-SPSS-better-tp5732642p5732818.html

Also for the record, I am not now, nor have I ever been an expert in the use
of CTABLES.  ;-)  



John F Hall wrote

> --- snip ---
>
> Bruce Weaver's original 2016 macro from Nabble thread "Making SPSS better"
>  
>
> * Encoding: UTF-8.
>
> DEFINE elaborate
>
> ( Y = !CHAREND('/') /
>
>    RowVar = !CHAREND('/') /
>
>    ColVar = !CMDEND ).
>
> CTABLES
>
>   /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]
>
>   /SLABELS POSITION=ROW VISIBLE=NO
>
>   /CATEGORIES VARIABLES= !y  TOTAL=YES
>
>   /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.
>
> !ENDDEFINE.
>
> --- snip ---





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Problems with CTABLES output

John F Hall
In reply to this post by Jon Peck

This works even better

 

 

CTABLES

  /TABLE sex  [C]   BY abany [C][rowpct.count f5.1 "%" totals [count "n= 100%"]]

  /CATEGORIES VARIABLES=abany TOTAL=YES.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

SEX Respondents sex

1 MALE

47.5

52.5

804

2 FEMALE

45.2

54.8

1006

 

 

CTABLES

  /TABLE partyid [C]  BY abany [C][rowpct.count f5.1 "%" totals [count "n= 100%"]]

  /CATEGORIES VARIABLES=abany TOTAL=YES.

 

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

PARTYID Political party affiliation

0 STRONG DEMOCRAT

56.9

43.1

311

1 NOT STR DEMOCRAT

52.7

47.3

313

2 IND,NEAR DEM

60.9

39.1

253

3 INDEPENDENT

41.4

58.6

285

4 IND,NEAR REP

38.2

61.8

170

5 NOT STR REPUBLICAN

36.3

63.7

240

6 STRONG REPUBLICAN

22.5

77.5

178

7 OTHER PARTY

56.8

43.2

44

 

From: [hidden email] <[hidden email]>
Sent: 28 April 2020 16:06
To: 'Jon Peck' <[hidden email]>; '[hidden email]' <[hidden email]>
Subject: RE: Problems with CTABLES output

 

That works fine, but it doesn’t explain why SPSS treats vote12 as scale when it’s nominal.  Will now attempt to modify Bruce’s macro again.

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Jon Peck
Sent: 28 April 2020 15:15
To: [hidden email]
Subject: Re: Problems with CTABLES output

 

Something like this will do it.

CTABLES
  /TABLE gender [C] > jobcat [C] BY minority [C][ROWPCT.COUNT TOTALS[COUNT]]
  /CATEGORIES VARIABLES=minority TOTAL=YES.

 

When you specify SLABELS POSITION=ROW

and there are different statistics for the totals (or other column variables), CTABLES puts each statistic type on a separate row so that they can be labelled correctly even though in this case you are suppressing the labels.

 

And, BTW, the gui is correct: you can't nest a scale variable under a scale variable - it wouldn't make sense.  But in syntax you can override the variable's measurement level by using [C].  You can do that in the gui by right clicking the variable in the Variables control before dragging it and setting the level, temporarily, to a categorical value.

 

On Tue, Apr 28, 2020 at 4:53 AM Joihn F Hall <[hidden email]> wrote:

I am reproducing some analysis from Babbie et al 2019, but using syntax rather than the GUI

(Which tells me I can’t nest scale variables, but they are all nominal).

 

The following syntax gets halfway to what I want.

 

 

CTABLES

/table postlife > vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

895

2 Did not vote

39.3

60.7

351

3 Ineligible

36.4

63.6

77

Total

40.8

59.2

1323

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

180

2 Did not vote

50.5

49.5

93

3 Ineligible

52.2

47.8

23

Total

64.5

35.5

296

Total

VOTE12 Did R vote in 2012 election

1 Voted

47.1

52.9

1075

2 Did not vote

41.7

58.3

444

3 Ineligible

40.0

60.0

100

Total

45.2

54.8

1619

 

Bruce Weaver’s original 2016 macro from Nabble thread “Making SPSS better”

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

27.8%

38.7%

100.0%

374

521

895

2 Did not vote

24.3%

37.6%

100.0%

138

213

351

3 Ineligible

20.3%

35.5%

100.0%

28

49

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

44.6%

16.2%

100.0%

132

48

180

2 Did not vote

30.3%

29.7%

100.0%

47

46

93

3 Ineligible

30.8%

28.2%

100.0%

12

11

23

NOTE:  Cells show ROWPCT and COUNT

 

 

Bruce Weaver’s macro modified

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c]

[rowpct.count f5.1 "%" totals [count "n= 100%"]] 

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

 

 

 

895

2 Did not vote

39.3

60.7

 

 

 

351

3 Ineligible

36.4

63.6

 

 

 

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

 

 

 

180

2 Did not vote

50.5

49.5

 

 

 

93

3 Ineligible

52.2

47.8

 

 

 

23

NOTE:  Cells show ROWPCT and COUNT

 

I can’t get the totals on the same line as the %%

The following syntax (from Weaver macro modified again)  puts 100% where I want the row total Ns.

 

 

CTABLES

/table postlife by vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason:   1 YES 

 

VOTE12 Did R vote in 2012 election

1 Voted

2 Did not vote

3 Ineligible

Total

%

%

%

%

POSTLIFE Belief in life after death

1 YES

69.3

25.6

5.2

100.0

2 NO

69.1

24.6

6.3

100.0

Total

69.2

25.3

5.5

100.0

 

Short of doing:

 

TEMP.

SELECT IF vote12 = 1.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

41.8

58.2

895

2 NO

73.3

26.7

180

Total

47.1

52.9

1075

 

 

TEMP.

SELECT IF vote12 = 2.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

39.3

60.7

351

2 NO

50.5

49.5

93

Total

41.7

58.3

444

 

Is there any way I can modify the macro to do this?   

 

I tried:

 

SORT CASES by vote12.

SPLIT FILE by vote12.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

But got:

 

Warnings

CATEGORIES: Variable vote12. The variable list specifies a scale variable or an undefined variable. The variable will be ignored.

The SPLIT FILE option LAYERED is ignored in Custom tables. To compare groups, use the split variables as the outermost row variables in the table.

 

Vote12 is Nominal, so what is SPSS playing at?  I went via GUI just to get the syntax from PASTE, but have been running syntax direct since.  Or is it because I’m not wearing a mask?

 

Thanks in advance for help.

 

John F Hall MA (Cantab) Dip Ed (Dunelm)

IBM-SPSS Academic Author 9900074

 

Email: [hidden email]

Website: Journeys in Survey Research

Course: Survey Analysis Workshop (SPSS)

 

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


 

--

Jon K Peck
[hidden email]

===================== 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: Problems with CTABLES output

Jon Peck
In reply to this post by John F Hall
I would have to see the data to be convinced that the measurement level is being treated incorrectly.  I have never heard of that happening before.

On Tue, Apr 28, 2020 at 8:06 AM <[hidden email]> wrote:

That works fine, but it doesn’t explain why SPSS treats vote12 as scale when it’s nominal.  Will now attempt to modify Bruce’s macro again.

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Jon Peck
Sent: 28 April 2020 15:15
To: [hidden email]
Subject: Re: Problems with CTABLES output

 

Something like this will do it.

CTABLES
  /TABLE gender [C] > jobcat [C] BY minority [C][ROWPCT.COUNT TOTALS[COUNT]]
  /CATEGORIES VARIABLES=minority TOTAL=YES.

 

When you specify SLABELS POSITION=ROW

and there are different statistics for the totals (or other column variables), CTABLES puts each statistic type on a separate row so that they can be labelled correctly even though in this case you are suppressing the labels.

 

And, BTW, the gui is correct: you can't nest a scale variable under a scale variable - it wouldn't make sense.  But in syntax you can override the variable's measurement level by using [C].  You can do that in the gui by right clicking the variable in the Variables control before dragging it and setting the level, temporarily, to a categorical value.

 

On Tue, Apr 28, 2020 at 4:53 AM Joihn F Hall <[hidden email]> wrote:

I am reproducing some analysis from Babbie et al 2019, but using syntax rather than the GUI

(Which tells me I can’t nest scale variables, but they are all nominal).

 

The following syntax gets halfway to what I want.

 

 

CTABLES

/table postlife > vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

895

2 Did not vote

39.3

60.7

351

3 Ineligible

36.4

63.6

77

Total

40.8

59.2

1323

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

180

2 Did not vote

50.5

49.5

93

3 Ineligible

52.2

47.8

23

Total

64.5

35.5

296

Total

VOTE12 Did R vote in 2012 election

1 Voted

47.1

52.9

1075

2 Did not vote

41.7

58.3

444

3 Ineligible

40.0

60.0

100

Total

45.2

54.8

1619

 

Bruce Weaver’s original 2016 macro from Nabble thread “Making SPSS better”

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

27.8%

38.7%

100.0%

374

521

895

2 Did not vote

24.3%

37.6%

100.0%

138

213

351

3 Ineligible

20.3%

35.5%

100.0%

28

49

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

44.6%

16.2%

100.0%

132

48

180

2 Did not vote

30.3%

29.7%

100.0%

47

46

93

3 Ineligible

30.8%

28.2%

100.0%

12

11

23

NOTE:  Cells show ROWPCT and COUNT

 

 

Bruce Weaver’s macro modified

 

* Encoding: UTF-8.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c]

[rowpct.count f5.1 "%" totals [count "n= 100%"]] 

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

POSTLIFE Belief in life after death

1 YES

VOTE12 Did R vote in 2012 election

1 Voted

41.8

58.2

 

 

 

895

2 Did not vote

39.3

60.7

 

 

 

351

3 Ineligible

36.4

63.6

 

 

 

77

2 NO

VOTE12 Did R vote in 2012 election

1 Voted

73.3

26.7

 

 

 

180

2 Did not vote

50.5

49.5

 

 

 

93

3 Ineligible

52.2

47.8

 

 

 

23

NOTE:  Cells show ROWPCT and COUNT

 

I can’t get the totals on the same line as the %%

The following syntax (from Weaver macro modified again)  puts 100% where I want the row total Ns.

 

 

CTABLES

/table postlife by vote12 by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason:   1 YES 

 

VOTE12 Did R vote in 2012 election

1 Voted

2 Did not vote

3 Ineligible

Total

%

%

%

%

POSTLIFE Belief in life after death

1 YES

69.3

25.6

5.2

100.0

2 NO

69.1

24.6

6.3

100.0

Total

69.2

25.3

5.5

100.0

 

Short of doing:

 

TEMP.

SELECT IF vote12 = 1.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

41.8

58.2

895

2 NO

73.3

26.7

180

Total

47.1

52.9

1075

 

 

TEMP.

SELECT IF vote12 = 2.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

POSTLIFE Belief in life after death

1 YES

39.3

60.7

351

2 NO

50.5

49.5

93

Total

41.7

58.3

444

 

Is there any way I can modify the macro to do this?   

 

I tried:

 

SORT CASES by vote12.

SPLIT FILE by vote12.

CTABLES

/table postlife by abany

[rowpct.count f5.1 "%" totals [count "n= 100%"]]

/categories variables = postlife vote12 abany total=yes position=after.

 

But got:

 

Warnings

CATEGORIES: Variable vote12. The variable list specifies a scale variable or an undefined variable. The variable will be ignored.

The SPLIT FILE option LAYERED is ignored in Custom tables. To compare groups, use the split variables as the outermost row variables in the table.

 

Vote12 is Nominal, so what is SPSS playing at?  I went via GUI just to get the syntax from PASTE, but have been running syntax direct since.  Or is it because I’m not wearing a mask?

 

Thanks in advance for help.

 

John F Hall MA (Cantab) Dip Ed (Dunelm)

IBM-SPSS Academic Author 9900074

 

Email: [hidden email]

Website: Journeys in Survey Research

Course: Survey Analysis Workshop (SPSS)

 

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


 

--

Jon K Peck
[hidden email]

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



--
Jon K Peck
[hidden email]

===================== 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: Problems with CTABLES output

John F Hall
In reply to this post by Bruce Weaver

Bruce is altogether too modest: he definitely wrote a macro for me, which I tweaked:

 

* Encoding: UTF-8.

*Bruce Weaver’s original macro.

DEFINE elaborate

( Y = !CHAREND('/') /

   RowVar = !CHAREND('/') /

   ColVar = !CMDEND ).

CTABLES

  /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]

  /SLABELS POSITION=ROW VISIBLE=NO

  /CATEGORIES VARIABLES= !y  TOTAL=YES

  /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

!ENDDEFINE.

* Read in some data to illustrate.

* Modify path on the FILE HANDLE command as needed.

* My tweak.

FILE HANDLE TheDataFile /NAME='C:\Users\John\Desktop\gss_2016\babbie2019.sav'.

 

* Call the macro.

elaborate Y = abany / RowVar = postlife / ColVar = vote12.

 

CROSSBREAK used to be a subcommand in BREAKDOWN (no longer available) which my students thought apposite for their struggles to understand SPSS syntax.  All I did then was recode a criterion value to 100 and everything else to 0.  The means then become %% and the output included the base N's for each cell.

 

[Extract from a really old tutorial, around 1983]

 

A particularly useful feature of the procedure is the ability  to display  means  etc.  in  the cells of  a  table  formed  by  the categories of two independent variables (e.g. sexism means by sex and race).  We do this using CROSSBREAK:

 

                MEANS   VARIABLES = SEXISM(0,9) V348(1,2)ETHNIC(1,2)

                                                /CROSSBREAK = SEXISM BY V348 BY ETHNIC

                /CELLS = MEAN COUNT

 

The output looks like this:

 

                    ETHNIC

              Mean :

             Count :  White      Black        Row     

                   :                         Total    

                   :       1  :       2  :

V348       --------:----------:----------:

                1  :     4.63 :     3.43 :     3.98

  Boys             :      19  :      23  :      42 

                  -:----------:----------:

                2  :     1.89 :     1.80 :     1.84

  Girls            :      19  :      25  :      44 

                  -:----------:----------:

     Column Total        3.26       2.58       2.88

                          38         48         86

 

A crafty use of CROSSBREAK in combination with RECODE allows  you to  display  percentages  instead  of  means  for  the  dependent variable.   What you do is to recode the value or values  of  the dependent  variable you are interested in to 100  and  everything else to 0.  The 'means' displayed are then percentages!  Thus:

 

                RECODE  SEXISM(2 THRU 7 = 100)(0,1 = 0)(ELSE = SYSMIS)

                MEANS   VARIABLES = SEXISM (0,100) V348 (1,2) ETHNIC (1,2)

                                /CROSSBREAK = SEXISM BY V348 BY ETHNIC

                /CELLS = MEAN COUNT

 

The output looks something like this:

 

                    ETHNIC

              Mean :

             Count :  White      Other        Row     

                   :                         Total    

                   :       1  :       2  :

V348       --------:----------:----------:

                1  :   100.00 :    82.61 :    90.48

  Boys             :      19  :      23  :      42 

                  -:----------:----------:

                2  :    47.37 :    44.00 :    45.45

  Girls            :      19  :      25  :      44 

                  -:----------:----------:

     Column Total       73.68      62.50      67.44

                          38         48         86

 

For the 2016 GSS:

 

 

compute abany2 = abany.

recode abany2 (2=100)(1=0).

means abany2  by sex partyid /cells mean count.

 

 

abany2  * SEX Respondents sex

abany2 

SEX Respondents sex

Mean

N

1 MALE

52.4876

804

2 FEMALE

54.7714

1006

Total

53.7569

1810

 

 

 

abany2  * PARTYID Political party affiliation

abany2 

PARTYID Political party affiliation

Mean

N

0 STRONG DEMOCRAT

43.0868

311

1 NOT STR DEMOCRAT

47.2843

313

2 IND,NEAR DEM

39.1304

253

3 INDEPENDENT

58.5965

285

4 IND,NEAR REP

61.7647

170

5 NOT STR REPUBLICAN

63.7500

240

6 STRONG REPUBLICAN

77.5281

178

7 OTHER PARTY

43.1818

44

Total

53.6789

1794

 

CTABLES does the same job:

 

 

CTABLES

  /TABLE sex  [C]   BY abany [C][rowpct.count f5.1 "%" totals [count "n= 100%"]]

  /CATEGORIES VARIABLES=abany TOTAL=YES.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

SEX Respondents sex

1 MALE

47.5

52.5

804

2 FEMALE

45.2

54.8

1006

 

 

CTABLES

  /TABLE partyid [C]  BY abany [C][rowpct.count f5.1 "%" totals [count "n= 100%"]]

  /CATEGORIES VARIABLES=abany TOTAL=YES.

 

 

 

ABANY Abortion if woman wants for any reason

1 YES

2 NO

Total

%

%

n= 100%

PARTYID Political party affiliation

0 STRONG DEMOCRAT

56.9

43.1

311

1 NOT STR DEMOCRAT

52.7

47.3

313

2 IND,NEAR DEM

60.9

39.1

253

3 INDEPENDENT

41.4

58.6

285

4 IND,NEAR REP

38.2

61.8

170

5 NOT STR REPUBLICAN

36.3

63.7

240

6 STRONG REPUBLICAN

22.5

77.5

178

7 OTHER PARTY

56.8

43.2

44

 

As noted by Babbie et al, the Independent (nearer Democrats) are more liberal than the strong Democrats!

 

 

 

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Bruce Weaver
Sent: 28 April 2020 16:20
To: [hidden email]
Subject: Re: Problems with CTABLES output

 

For the record, I had no recollection of writing a macro called ELABORATE.

It turns out I didn't.  I wrote a macro called CrossBreak.  John subsequently tweaked it and renamed it ELABORATE. 

 

http://spssx-discussion.1045642.n5.nabble.com/Making-SPSS-better-tp5732642p5732775.html

http://spssx-discussion.1045642.n5.nabble.com/Making-SPSS-better-tp5732642p5732818.html

 

Also for the record, I am not now, nor have I ever been an expert in the use of CTABLES.  ;-) 

 

 

 

John F Hall wrote

> --- snip ---

>

> Bruce Weaver's original 2016 macro from Nabble thread "Making SPSS better"

>

> * Encoding: UTF-8.

>

> DEFINE elaborate

>

> ( Y = !CHAREND('/') /

>

>    RowVar = !CHAREND('/') /

>

>    ColVar = !CMDEND ).

>

> CTABLES

>

>   /TABLE !RowVar  [C] >  !ColVar [C] by !Y [c] [ROWPCT.totaln, COUNT]

>

>   /SLABELS POSITION=ROW VISIBLE=NO

>

>   /CATEGORIES VARIABLES= !y  TOTAL=YES

>

>   /TITLES CAPTION ='NOTE:  Cells show ROWPCT and COUNT'.

>

> !ENDDEFINE.

>

> --- snip ---

 

 

 

 

 

-----

--

Bruce Weaver

[hidden email]

http://sites.google.com/a/lakeheadu.ca/bweaver/

 

"When all else fails, RTFM."

 

NOTE: My Hotmail account is not monitored regularly.

To send me an e-mail, please use the address shown above.

 

--

Sent from: http://spssx-discussion.1045642.n5.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