One of the most common research questions is do different groups have different mean scores on some variable? This question is best answered in 3 steps:
- create a table showing mean scores per group -you'll probably want to include the frequencies and standard deviations as well;
- create a chart showing mean scores per group;
- run some statistical test -ANOVA in this case. However, this is only meaningful if your data are (roughly) a simple random sample from your target population.
We'll show the first 2 steps using an employee survey whose data are in bank-clean.sav. The screenshot below shows what these data basically look like.
Creating a Means Table
For creating a table showing means per category, we could mess around with syntax is as simple as it gets. So let's just run it and inspect the result.
but its not worth the effort as themeans q1 by jtype
/cells count mean stddev.
Note that you could easily add more statistics to the CELLS subcommand such as
Result
Basically, our table tells us that the mean employee care ratings increase with higher job levels except for “upper management”. A proper descriptives table -always recommended- gives nicely detailed information. However, it's not very visual. So let's now run our chart.
SPSS Bar Chart Menu & Dialogs
As a rule of thumb, I create all charts from stacked bar chart with percentages.
and avoid the Chart Builder whenever I can -which is pretty much always unless I need a
In the dialog shown below, selecting
Basic Bar Chart Means by Category Syntax
GRAPH
/BAR(SIMPLE)=MEAN(q1) BY jtype
/TITLE='Mean Employee Care Rating by Job Type'
/SUBTITLE='N = 423'.
Result
We now have our basic chart but it doesn't look too good.From SPSS version 25 onwards, it will look somewhat better. However, see New Charts in SPSS 25 - How Good Are They Really? Yet. We'll fix this by setting a chart template.
Note that a chart template can also sort this bar chart -for instance by descending means- but we'll skip that for now.
Bar Chart Means by Category Syntax II
set ctemplate "bar-chart-means-trans-720-1.sgt".
*Rerun chart with template set.
GRAPH
/BAR(SIMPLE)=MEAN(q1) BY jtype
/TITLE='Mean Employee Care Rating by Job Type'
/SUBTITLE='N = 423'.
Result
Right, so that's about it. If you need a couple of similar charts, you could copy-paste-edit the last GRAPH command (no need to repeat the other commands). If you need many similar charts, you could loop over the GRAPH command with Python for SPSS.
If you're going to run other types of charts, don't forget to set a different chart template. Or switch if off altogether by running set ctemplate none.
Thanks for reading!
THIS TUTORIAL HAS 12 COMMENTS:
By David Marso on July 11th, 2018
"If you need many similar charts, you could loop over the GRAPH command with Python."
Or not to be heretical old fashioned or obstinate a simple macro would suffice. Why are people so damned obsessed with python?
By Ruben Geert van den Berg on July 12th, 2018
Just writing out all syntax manually suffices too.
But -just like SPSS macros- it's just hopelessly inefficient.
For one thing, macros know nothing whatsoever about either your dictionary or your data values. They can't even look up a range of variable names.
Python does this -and many other things that macros can't- with a mere handful of clean and readable code.
Perhaps you should give it a try some time.
By Arsh on January 11th, 2019
Bar charts are great. Great work showing how to make bar charts with means by category.
By Ruben Geert van den Berg on January 11th, 2019
Hi Arsh, thanks for the compliment!
You might like SPSS - Stacked Bar Charts Percentages as well. However, these charts really need to be transposed and styled, both of which you can do with chart templates.
Enjoy your weekend!
SPSS tutorials
By Petter on May 28th, 2020
Hi! How do i make the bar chart to include empty categories?