Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: multigroup histogram
From
Austin Nichols <[email protected]>
To
[email protected]
Subject
Re: st: multigroup histogram
Date
Mon, 3 Jan 2011 18:24:09 -0500
tigerstale <[email protected]>:
Here is an example that may light the way...
ssc inst byhist, replace
clear all
sysuse nlsw88
byhist grade, by(race) disc name(freq)
byhist grade, by(race) disc frac name(frac)
twoway__histogram_gen grade, gen(f g) disc
loc w=r(width)/2
levelsof g, loc(gs)
tokenize `gs'
loc 0 -1e233
loc N: word count `gs'
qui forv j=0/3 {
g h`j'=.
la var h`j' "`:label (race) `j''"
}
la var h0 "All races"
qui forv i=1/`N' {
loc lb=``i''-`w'
loc ub=``i''+`w'-c(epsfloat)
forv j=0/3 {
if `j'>0 count if race==`j'&inrange(grade,`lb',`ub')
else count if inrange(grade,`lb',`ub')
replace h`j'=r(N) if _n==`i'
}
}
tw bar h1 g,barw(`w')||sc h2 g||sc h3 g,name(freq2)
tw bar h0 g,barw(`w')||sc h1 g||sc h2 g,name(freq0)
qui forv j=0/3 {
egen sh`j'=sum(h`j')
replace sh`j'=h`j'/sh`j'
la var sh`j' "`:var label h`j''"
}
tw bar sh1 g,barw(`w')||sc sh2 g||sc sh3 g,name(frac2)
tw bar sh0 g,barw(`w')||sc sh1 g||sc sh2 g,name(frac0)
On Mon, Jan 3, 2011 at 5:12 PM, tigerstale <[email protected]> wrote:
> Hello. I'm trying to generate a multi-group bar graph. Specifically, I want
> the main graph to show the frequency distribution across a categorical
> variable (23 occupational categories); I then want to superimpose
> circles/diamonds representing the same distribution for subgroups
> (black/white). In other words, the primary bar graph (histogram) would
> represent the frequency distribution for the full sample; there would be
> circles to indicate where the frequencies would fall for blacks and diamonds
> to indicate where the frequencies would fall for whites.
>
> Any suggestions?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/