I have a really nice .do file based primarily on putexcel that summarizes a bunch of six-value scale variables, including tiny little histograms. The survey instrument is generally administered to small groups at a time, maybe eight to twenty people. It's basically an employee satisfaction scale, so there are very few who admit to being really negative, and very few who choose the highest category.
As far as I can tell, if every category has a response, my histograms are fine. But if a category is skipped, the histograms don't come out right; especially that people get shifted to the highest category. Below I have posted some example data, and the problematic part of my command file. If it would be useful I can post the whole command file, but the rest of it (including placing the tiny little histograms into Excel) seems to work just fine.
I have tried all kinds of options with hist to no avail. Every time I think I have the histograms right, one or a few of them are mangled. The options chosen below are certainly not the right ones. Remember: these are generated on small sample sizes, often with truncated data.
generating histograms:
As far as I can tell, if every category has a response, my histograms are fine. But if a category is skipped, the histograms don't come out right; especially that people get shifted to the highest category. Below I have posted some example data, and the problematic part of my command file. If it would be useful I can post the whole command file, but the rest of it (including placing the tiny little histograms into Excel) seems to work just fine.
I have tried all kinds of options with hist to no avail. Every time I think I have the histograms right, one or a few of them are mangled. The options chosen below are certainly not the right ones. Remember: these are generated on small sample sizes, often with truncated data.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(q2_1 q2_2 q2_3 q2_4 q2_5 q3_1 q3_2 q3_3 q3_4 q3_5 q4_1 q4_2 q4_3 q4_4 q4_5 q5_1 q5_2 q5_3 q5_4 q5_5 q6_1 q6_2 q6_3 q6_4 q6_5) 2 1 6 4 1 2 0 1 2 6 6 3 2 4 2 5 3 2 4 3 2 2 2 0 0 3 2 3 2 2 3 2 4 1 2 3 1 4 4 6 2 4 2 3 2 3 4 3 1 3 1 4 3 3 3 2 2 3 2 5 2 2 0 3 2 5 2 2 0 3 1 0 2 0 4 4 4 4 3 3 4 0 0 2 3 2 3 3 3 4 3 3 0 0 2 2 2 2 2 1 2 4 2 0 0 5 4 6 4 2 2 2 6 4 3 4 2 1 4 0 6 2 2 0 4 6 2 2 1 3 2 2 0 1 3 2 2 1 4 2 0 2 4 2 2 2 2 3 3 2 1 3 6 2 3 6 3 0 3 6 3 2 4 5 4 1 3 4 2 3 2 4 3 1 4 end
Code:
gen tmp=. *======reverse-coding and generating histograms foreach var of varlist q2_1-q6_5 { replace `var'=6-`var' replace tmp=`var' hist tmp, bin(6) color(blue) ylabel(none) xlabel(none) start(0) sum tmp graph export `var'.png, as(png) replace wid(100) hei(40) } drop tmp
Comment