# SPSS Statistics

View Only

## GRAPH command: denominator for percentages

• #### 1.  GRAPH command: denominator for percentages

Posted Thu January 25, 2024 07:35 AM
Edited by Frank Furter Thu January 25, 2024 07:36 AM

Using the GRAPH command (not GGRAPH) for generating a stacked bar chart, how can I specify the denominator for computing percentages?

Background: I would like to create a stacked bar graph that shows the percent frequency of categories within subgroups defined by the variable on the x-axis. My subroups have different numbers of subjects. In order to compare the relative frequencies in the categories, the cumulative percentage in each stack should be 100%, i.e., the denominator should be the total nmumber of cases in each category on the x-axsis. I would like to use the GRAPH command for this because, contrary to GGRAPH, it can be conveniently integrated into SPSS define ... !enddefine macros (no, I do not want to re-program all my stuff in Python ...).

Moreover, I'm not sure which denominator GRAPH actually uses: stacks have different sizes, and the cumulatrive percentage within each stack often exceeds 100%. What is this supposed to mean?

------------------------------
Frank Furter
------------------------------

• #### 2.  RE: GRAPH command: denominator for percentages

Posted Fri February 09, 2024 12:52 PM

Hi @Frank Furter,
You are correct.  The GRAPH command and the associated legacy graphs (Graph -> Bar) menus do not give you that level of granularity.

By contrast, the GGRAPH command and associated Chart Builder graphs (Graphs -> Chart Builder -> Bar) do give you a choice for the percentages reported.

The GRAPH command is giving you the third type of graph in that GGRAPH dropdown - "Total for Each Legend Variable Category (same fill color)"
I suspect what you want is one of the other two.  Attached is output and the GGRAPH command that created it (I took the options for the denominator in order when I created these graphs).

I hope this helps,

------------------------------
David Dwyer
SPSS Technical Support
IBM Software
------------------------------

Attachment(s)

GRAPHvGRAPH.htm   182 KB 1 version

• #### 3.  RE: GRAPH command: denominator for percentages

Posted Sat February 10, 2024 05:52 AM
Edited by Frank Furter Sat February 10, 2024 05:52 AM

Hi David,

thank you for your message - I am fully aware that this can be done in GGRAPH. The trouble is that I use quite a lot of SPSS macros (and I have a nice, little library) for repetitive tasks, and the GGRAPH does not run inside a DEFINE ... !ENDDEFINE structure. This is very unfortunate ...

------------------------------
Frank Furter
------------------------------

• #### 4.  RE: GRAPH command: denominator for percentages

IBM Champion
Posted Sat February 10, 2024 09:46 AM
One solution would be to convert these macros into Python code, which can handle GGRAPH.  I can't say whether that would be easy or hard without seeing the code, but I could take a look if you want to consider that.

--

• #### 5.  RE: GRAPH command: denominator for percentages

Posted Sat February 10, 2024 11:11 AM

Thank you so much for your kind offer, @Jon Peck, but I have tons of define ... !enddefine macros that would have to be converted. Plus, I am not proficient enough in Python. Maybe I should nevertheless teach this old dog the new tricks (I started using SPSS on a mainframe with punch cards ;) ) ...

------------------------------
Frank Furter
------------------------------

• #### 6.  RE: GRAPH command: denominator for percentages

Posted Mon February 12, 2024 01:31 AM
Edited by Kirill Orlov Mon February 12, 2024 01:44 AM

GGRAPH runs inside macro definition. BEGIN GPL block does not, but it can be included via GRAPHSPEC='file' on GGRAPH. The file can be created earlier right in the same macro by WRITE command. Or created in advance and stored. I see no much problem using GGRAPH with macros.

------------------------------
Kirill Orlov
------------------------------

• #### 7.  RE: GRAPH command: denominator for percentages

Posted Mon February 12, 2024 04:26 AM
Edited by Kirill Orlov Mon February 12, 2024 04:29 AM

You can get the percent you want (total = each X axis category) through the stacked GRAPH barchart via editing the produced graph.

1. Create the stacked barchart as you did, but with Count (N of cases) rather than Percent to display.
2. Open the graph and check Options - Scale to 100%.
3. Check Elements - Show data labels.
4. Click on any label appeared and, in the Properties dialog box, on Data Value labels tab, request Percent to display. Ready.

To somewhat automate these editing steps, you can save the .sgt template. It will apply the said actions once you created the the graph.

------------------------------
Kirill Orlov
------------------------------