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.
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.
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.
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.
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.
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.
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:
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) |
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:
|
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 Something like this will do it. CTABLES 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:
-- Jon K Peck ===================== 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 |
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/). |
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.
CTABLES /TABLE partyid [C] BY abany [C][rowpct.count f5.1 "%" totals [count "n= 100%"]] /CATEGORIES VARIABLES=abany TOTAL=YES.
From: [hidden email] <[hidden email]> 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 Something like this will do it. CTABLES 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:
-- Jon K Peck ===================== 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 |
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:
|
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.
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.
CTABLES /TABLE partyid [C] BY abany [C][rowpct.count f5.1 "%" totals [count "n= 100%"]] /CATEGORIES VARIABLES=abany TOTAL=YES.
As noted by Babbie et al, the Independent (nearer Democrats) are more liberal than the strong Democrats! -----Original Message----- 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 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 |
Free forum by Nabble | Edit this page |