How can a have a graph show categories with 0 frequency?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How can a have a graph show categories with 0 frequency?

bia-2

Hello!

I have a very simple but urgent question and I would appreciate so much an answer. I have a simple bar graph for an ordinal variable (1=not at all .... 6= very much)  and one of the categories (1=not at all)  has 0 frequency (no subject has chosen that one.). How can I have that category represented in the graph, even though its frquency is 0?

Thank you very much!

Bia 


Reply | Threaded
Open this post in threaded view
|

Re: How can a have a graph show categories with 0 frequency?

Ruben Geert van den Berg
Dear Bia,
 
There may be a neater method (like a Python extension but I'm not sure) but the classical solution is to add one case and weight it to almost zero. This also works for frequency tables. For an example, see below.
 
HTH,

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com

*Generate test data.
 
input program.
loop id=1 to 100.
compute v1=rnd(rv.uni(.5,3.5)).
end case.
end loop.
end file.
end input program.
execute.
 
variable label v1 'favorite pet'.
add value labels v1 0 'cat'1'dog'2'turtle'3'other'.
 
dataset name d1.
 
graph /bar=v1.
 
*No cat in the graph. Assuming you have no weighting variable, all your normal cases should count as one case.
 
compute weight=1.
 
*Now we create a single phantom case who prefers a cat and we give her a virtually zero weight.
 
data list free/v1 weight.
begin data
0 1e-15
end data.
 
*Now we add this case to the original data.
 
add files file *
/file=d1.
execute.
 
*Now we activate the weighting variable.
 
weight by weight.
 
*And now cat is included with zero frequency.
 
graph /bar=v1.



 

Date: Mon, 7 Jun 2010 02:32:00 -0700
From: [hidden email]
Subject: How can a have a graph show categories with 0 frequency?
To: [hidden email]

Hello!
I have a very simple but urgent question and I would appreciate so much an answer. I have a simple bar graph for an ordinal variable (1=not at all .... 6= very much)  and one of the categories (1=not at all)  has 0 frequency (no subject has chosen that one.). How can I have that category represented in the graph, even though its frquency is 0?
Thank you very much!
Bia 



Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: How can a have a graph show categories with 0 frequency?

Garry Gelade
In reply to this post by bia-2

HI Bia

 

You can do this easily in chart builder.  Just make sure your ordinal variable is defined as Ordinal (i.e. on the Variable View tab of the Data Editor, set the Measure for that variable to Ordinal). Then make sure you have entered value labels for every value of the ordinal variable you want to display in your chart.

 

That’s it. You can then produce a histogram or a bar chart which will show all values of the ordinal variable even ones with zero frequency.

 

Garry Gelade

Business Analytic Ltd

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bia
Sent: 07 June 2010 10:32
To: [hidden email]
Subject: How can a have a graph show categories with 0 frequency?

 

Hello!

I have a very simple but urgent question and I would appreciate so much an answer. I have a simple bar graph for an ordinal variable (1=not at all .... 6= very much)  and one of the categories (1=not at all)  has 0 frequency (no subject has chosen that one.). How can I have that category represented in the graph, even though its frquency is 0?

Thank you very much!

Bia 

 

Reply | Threaded
Open this post in threaded view
|

Re: How can a have a graph show categories with 0 frequency?

Jon K Peck
In reply to this post by Ruben Geert van den Berg

You can specify the categories to appear in the chart explicitly using GPL.  Paste your bar chart syntax from the Chart Builder, and you will see a SCALE statement similar to the following

  SCALE: cat(dim(1), include("1", "2", "3"))

You can add other categories as needed to the include portion of the statement.

HTH,

Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Ruben van den Berg <[hidden email]>
To: [hidden email]
Date: 06/07/2010 04:14 AM
Subject: Re: [SPSSX-L] How can a have a graph show categories with 0              frequency?
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Dear Bia,

There may be a neater method (like a Python extension but I'm not sure) but the classical solution is to add one case and weight it to almost zero. This also works for frequency tables. For an example, see below.

HTH,

Ruben van den Berg

Consultant Models & Methods

TNS NIPO

Email: [hidden email]

Mobiel: +31 6 24641435

Telefoon: +31 20 522 5738

Internet:
www.tns-nipo.com

*Generate test data.

input program.
loop id=1 to 100.
compute v1=rnd(rv.uni(.5,3.5)).
end case.
end loop.
end file.
end input program.
execute.

variable label v1 'favorite pet'.
add value labels v1 0 'cat'1'dog'2'turtle'3'other'.

dataset name d1.

graph /bar=v1.

*No cat in the graph. Assuming you have no weighting variable, all your normal cases should count as one case.

compute weight=1.

*Now we create a single phantom case who prefers a cat and we give her a virtually zero weight.

data list free/v1 weight.
begin data
0 1e-15
end data.

*Now we add this case to the original data.

add files file *
/file=d1.
execute.

*Now we activate the weighting variable.

weight by weight.

*And now cat is included with zero frequency.

graph /bar=v1.





Date: Mon, 7 Jun 2010 02:32:00 -0700
From: [hidden email]
Subject: How can a have a graph show categories with 0 frequency?
To: [hidden email]
Hello!
I have a very simple but urgent question and I would appreciate so much an answer. I have a simple bar graph for an ordinal variable (1=not at all .... 6= very much)  and one of the categories (1=not at all)  has 0 frequency (no subject has chosen that one.). How can I have that category represented in the graph, even though its frquency is 0?
Thank you very much!
Bia




Express yourself instantly with MSN Messenger! MSN Messenger