Creating histogram within variables - labels

#1
Hey guys.

I have a dataset with 6 different job categories and a simple yes/no-answer to a question. My data is coded in two variables; job-type and yes/no. That means, that I've labeled 1,2,3,4,5,6 in Job-types with job names and 1 and 2 in answer variable to yes/no.

What I don't know is, that if I want to ex. to show only, lets say, two different job-types and their answers in a histogram and thereby comparing them visually (and disregarding the rest for this small graphic), what do I do? I'd like to know the command to just show the data for one or two labels in a variable as well; ex. to, in numbers do the same as in graphics. I simply don't know how to do a "tab label". It doesn't really work for me - it just say: "variable "label" not found". And I get that; I don't have that variable, but I wan't it to show the label data instead.
 

bukharin

RoboStataRaptor
#2
It sounds like you're after a bar graph rather than a histogram; use -graph bar-

Let's say your variables are called jobtype1-jobtype6 and each one is encoded as a binary variable (0=no, 1=yes). You could then generate a bar graph using eg:
graph bar (sum) jobtype1 jobtype2

And the table is as simple as:
tab jobtype1 jobtype2

Of course, all of the above will look a lot better if your variables are labelled properly; see -help label- and the relevant sections of the Getting Started manual and User's Guide.
 
#3
No because that is my problem; there is only two variables. One with numbers 1-6 with each number corrolating to a job-type and the other 1 and 2 for yes no. I needed to define the numbers inside the variable with jobtypes (labels) so everytime I tab job, i hey all six labels (jobtypes). I was hoping, that I could tab a single label inside the variable.
 

bukharin

RoboStataRaptor
#4
In that case you can use the -if- qualifier to restrict observations to the job of interest:
tab answer if jobtype==1
and
graph bar (sum) answer if jobtype==1
or even
graph bar (sum) answer, over(jobtype)

The above graph commands will show the sum of your answers (1 and 2), which is not what you want - first you should -recode- this variable so that 0=no and 1=yes - that way the sum is the number of people with that job type, or alternatively, the mean is the proportion of people with that job type.