Hi all,
I am using --catplot-- with Stata 14.1. The dataex output to create sample data is at the bottom of this post.
I am trying to produce a simple graph of the percent of respondents on a survey who gave different responses to a multiple choice question. My code is below, and the graph it produces follows (note that the color is set by a scheme provided by my job).

I have two questions:
(1) I would like to reduce the font size of the labels on the x-axis, as well as make the text fall on multiple lines, so that they no longer overlap. I have successfully done this using the "yvaroptions" option in the --graph bar-- command previously (hence I included it in my code), but when using it here with catplot, it seems to have no impact on the appearance of these labels. Is there a way to do this with catplot? I can change the scale but wondered if it was possible to affect these more directly.
(2) As you'll note in the data, there are response options (eg "Local government resources") which none of the survey respondents selected, so they are not showing up in the graph. I would like to still have these categories show up, as zero % (ie, a space on the graph), so that viewers know that that response was an option but no one picked it. I thought the "allcategories" option would do this, but it seems to have had no impact. Is there a way to do this?
Thank you all very much in advance for your help.
Julia
I am using --catplot-- with Stata 14.1. The dataex output to create sample data is at the bottom of this post.
I am trying to produce a simple graph of the percent of respondents on a survey who gave different responses to a multiple choice question. My code is below, and the graph it produces follows (note that the color is set by a scheme provided by my job).
Code:
mylabels 0(20)100, myscale(@) local(pctlabel) suffix("%") splitvallabels q6, length(5) nobreak recode catplot q6, missing allcategories recast(bar) percent /// xsize(3) ysize(2.2) scale(1) ytitle("Percent") /// ylabel(`pctlabel') b1title("") yvaroptions(relabel(`r(relabel)') label(labsize(vsmall))) outergap(*3.5) /// saving("$data\5_Analysis\6_q6.gph", replace)
I have two questions:
(1) I would like to reduce the font size of the labels on the x-axis, as well as make the text fall on multiple lines, so that they no longer overlap. I have successfully done this using the "yvaroptions" option in the --graph bar-- command previously (hence I included it in my code), but when using it here with catplot, it seems to have no impact on the appearance of these labels. Is there a way to do this with catplot? I can change the scale but wondered if it was possible to affect these more directly.
(2) As you'll note in the data, there are response options (eg "Local government resources") which none of the survey respondents selected, so they are not showing up in the graph. I would like to still have these categories show up, as zero % (ie, a space on the graph), so that viewers know that that response was an option but no one picked it. I thought the "allcategories" option would do this, but it seems to have had no impact. Is there a way to do this?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str17 v1 byte q6 "R_2" 6 "R_3" .r "R_4" 1 "R_5" 1 "R_6" 2 "R_1" 1 end label values q6 labq6 label def labq6 1 "State resources", modify label def labq6 2 "Federal resources", modify label def labq6 3 "Local government resources", modify label def labq6 5 "Fees from service providers", modify label def labq6 6 "Mixed sources", modify label def labq6 .r "Respondent missing", modify label var v1 "ResponseID" label var q6 "How is your infant mortality organizing/planning group funded"
Thank you all very much in advance for your help.
Julia
Comment