1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
SPSS AnswerNet: Result Solution ID: 100001386 Product: SPSS Base Version: O/S: WINDOWS Question Type: Graphics Question Subtype: Creation Title: Blank bar for unselected category Description: Q. I have a categorical variable which I would like to display in a bar chart. However, one of my categories was not selected by any of my respondents. I can generate a frequency distribution and bar chart for this variable, but the unselected category is not included. How can I both generate a frequency distribution to show a zero count for this category, as well as generate a bar chart which also reflects a zero frequency? A. This is not a hard project. First, you'll need to create a constant with a value of 1 to weight the cases in the data set by. After you create that constant, save the data file. Then, create another data set with a DATA LIST command. This new file will have only one case. This case will contain the variable you wish to chart (with the value that you wish to include in the chart) and the weight variable. The weight variable should have a very small value, like .00001. Then, merge this data set with the original, WEIGHT BY weight variable, and then generate the chart either through the FREQUENCIES command, or with GRAPH. You'll get a frequency of 0 for that value, and the resultant bar chart will have a "blank" space for the bar. The following sample job is illustrative: * Create a sample data set. INPUT PROGRAM. LOOP #I = 1 TO 100. COMPUTE x = (TRUNC(UNIFORM(3)) + 1). END CASE. END LOOP. END FILE. END INPUT PROGRAM. EXECUTE. * Compute the weight variable. COMPUTE weight = 1. SAVE OUTFILE = 'TMP.SAV'. * Create a new file to merge with the original data. NEW FILE. DATA LIST /x 1 weight 3-8. BEGIN DATA 4 .00001 END DATA. EXE. * Merge the data. ADD FILES /FILE=* /FILE='TMP.SAV'. EXECUTE. * Weight the data. WEIGHT BY weight . * Generate the chart, here done with the FREQUENCIES command. FREQUENCIES VARIABLES=x /BARCHART FREQ.