I am using Stata 14.1 on Windows 7.
I am attempting to create stacked bar graphs of student performance on specific items within an assessment. I'd like to have the categories be the specific items (1-10 for some subtests; 1-60 for others; 1-100 for yet others) and have the y-values be (a) proportion of students attempting the item, and (b) proportion of children answering correctly. (Or # in lieu of proportion - still deciding on that. But that's the easy part, so not the focus of this question.)
For the tasks with few items, I've been able to generate beautiful [except for the typo in the legend - curse that stuck 'L' key] graphs that look exactly the way I'd like them to using the -graph bar- approach... (See attachment one.)
But then when the number of items gets huge, the labels mangle each other and the width of the bars shrinks down to tiny. (See attachment two.)
The code I'm using for this is below:
I've read in various places around Statalist and Stack Overflow that Nick recommends moving to -twoway bar- for this kind of issue. I've attempted to do so, but am making an absolute hash of it. (See attachment three.) 
And I really am not sure where I'm going wrong in my various attempts to tweak the code. The code I'm attempting to use for the -twoway- approach is below:
Note also that I'm currently commenting out the -name()- option in both of these because I keep getting an error message ("Phonemic Awareness - invalid name"). I've tried replacing all spaces with underscores, etc. and am not resolving the issue. I don't think I'm running into a character limit issue, but I'm too fried to figure out what else it might be.
My goal would be to replicate the look of screenshot 1 for subtests with as many items as in screenshot 2: clean spacing, enough room for the in-bar labels to be legible, and either enough spacing for the x-labels to be legible or the capacity to only label every nth category. When I do this exercise manually in Excel, I can get the look I want simply by extending the graph's width beyond the borders of my screen and then zooming out to grab my screencap. Obviously that's kludgy...but it also got me wondering whether I could somehow define the 'canvas' that Stata writes to as so wide that everything would sort of auto-fit nicely. Didn't have any luck with that, either.
I am attempting to create stacked bar graphs of student performance on specific items within an assessment. I'd like to have the categories be the specific items (1-10 for some subtests; 1-60 for others; 1-100 for yet others) and have the y-values be (a) proportion of students attempting the item, and (b) proportion of children answering correctly. (Or # in lieu of proportion - still deciding on that. But that's the easy part, so not the focus of this question.)
For the tasks with few items, I've been able to generate beautiful [except for the typo in the legend - curse that stuck 'L' key] graphs that look exactly the way I'd like them to using the -graph bar- approach... (See attachment one.)
But then when the number of items gets huge, the labels mangle each other and the width of the bars shrinks down to tiny. (See attachment two.)
The code I'm using for this is below:
Code:
graph bar ans_correct_ct ans_incorrect_ct if grade==`g' & language==`lang', over(item) bar(1, color(usaid_red) lcolor(black)) bar(2, color(usaid_darkgray) lcolor(black)) /// blabel(total, position(inside) format(%2.0f) color(white) /*size(5)*/) stack /// title("# of learners attempting and correctly answering" "each item of the ``subtest'_proper' subtest") /// note("Source: Learner Assessment Test in `district_proper', October 2015") /// legend(label(1 "# learners answering correctly") label(2 "# learners attempting")) graphregion(color(white)) // name(PhonemicAwareness - `lang_`lang'_proper' - Grade `g' - District `district') //name(``subtest'_proper' - `lang_`lang'_proper' - Grade `g' - District `district'
And I really am not sure where I'm going wrong in my various attempts to tweak the code. The code I'm attempting to use for the -twoway- approach is below:
Code:
graph twoway /// (bar ans_correct_ct item if grade==`g' & language==`lang', barw(5) bcolor(usaid_red) lcolor(black)) /// rbar ans_incorrect_ct ans_correct_ct item if grade==`g' & language==`lang', barw(5) bcolor(usaid_darkgray) lcolor(black) /// /*blabel(total, position(inside) format(%2.0f) color(white) /*size(5)*/) stack*/ /// title("# of learners attempting and correctly answering" "each item of the ``subtest'_proper' subtest") /// note("Source: Learner Assessment Test in `district_proper', October 2015") /// legend(label(1 "# learners answering correctly") label(2 "# learners attempting")) graphregion(color(white)) /// /*name(``subtest'_proper'-`lang_`lang'_proper'-Grade`g'-District-`district')*/
My goal would be to replicate the look of screenshot 1 for subtests with as many items as in screenshot 2: clean spacing, enough room for the in-bar labels to be legible, and either enough spacing for the x-labels to be legible or the capacity to only label every nth category. When I do this exercise manually in Excel, I can get the look I want simply by extending the graph's width beyond the borders of my screen and then zooming out to grab my screencap. Obviously that's kludgy...but it also got me wondering whether I could somehow define the 'canvas' that Stata writes to as so wide that everything would sort of auto-fit nicely. Didn't have any luck with that, either.
Comment