FAQ/bar - CBU statistics Wiki

Please enter your password of your account at the remote wiki below.
/!\ You should trust both wikis because the password could be read by the particular administrators.

Clear message
location: FAQ / bar

Empty categories in a SPSS bar graph

A bar graph for groups (in variable group) may be produced in SPSS using the syntax below

WEIGHT BY freq.
GRAPH
  /BAR(SIMPLE)=COUNT BY group.

If there is raw data in the graph for which we wish to obtain a bar graph perhaps split by group (e.g. a bar graph of the number of diary entries made by members of a control group or intervention group) then we don't need to use the weight command and can use graphs>chart builder choosing the stacked bar graph and placing the diary counts on the x-axis bar graph and the group to represent the colour of each bar (in the top right corner). After running clicking on any bar and choosing Options>Bin element (so the Binning tab is highlighted) then 'custom' and entering the desired number of distinct bars e.g. in order to produce a bar for each person.

If a rating scale has a category which doesn’t occur, e.g. ‘Impaired’, this category is not shown in bar charts. This can be a disadvantage, for example, in checking for Normality or even getting an impression of the complete range of possible data values. This can be overcome by weighting the cases.

Example Let’s suppose we wish to graph group frequencies, for abilities on a particular task on a simple bar chart. Nobody is classed as 'impaired'. We, therefore, add a second variable, wdat, containing the frequencies and a small positive value, for example 0.001, for the non-occurring impaired group. This group will now be represented in the bar chart. The bar chart may be edited in the output window by clicking on particular portions.

[THE SPSS SYNTAX IN THE BOX BELOW CAN BE PASTED INTO A SPSS SYNTAX WINDOW AND RUN; THE DATA MAY BE AMENDED AS REQUIRED]

* in the below the groups are defined by fdat with total 
* frequencies (summed over individuals) wdat. If raw (individual)
* data is entered  wdat takes value ‘1’ for each observed data 
* point and ‘0.001’ for any data points which could have occurred * but did not.

Data list free/
Fdat wdat.
Begin data
1 0.001
2 2
3 10
4 5
end data.

VAR LABELS      FDAT     ABILITY/
                WDAT     WEIGHT /.  

VALUE LABELS   FDAT (1) IMPAIRED
                    (2) BELOW AVERAGE
                    (3) AVERAGE
                    (4) ABOVE AVERAGE.

DEFINE !MYBAR          (!POS !TOKENS(1)
                      / !POS !TOKENS(1)   
                      / !POS !CMDEND).
WEIGHT BY !2 .
GRAPH TITLE=!QUOTE(!3)
  /BAR(SIMPLE)=COUNT BY !1
  /MISSING=REPORT.
!ENDDEFINE.

!MYBAR FDAT WDAT DISTRIBUTION OF ABILITY GROUPS. 

* Multiple invocations of the macro in the same interactive session will produce the following note:

>The macro name specified on the DEFINE command duplicates the name of a previously defined macro. This instance will take precedence.

This warning does not indicate a problem and may be ignored.