Good question. My answer: you need a different data structure first.
Warning: this destroys your data.
Assume variables v1-v7. Then consider
gen id = _n
reshape long v, i(id)
contract v _j , zero
graph hbar (asis) _freq , over(_j) over(v)
You may do need to do some renaming to get the names in a suitable state
for -reshape-.
I used the -hbar- choice because for your problem with 28 bars,
legibility will be an issue with -graph bar-.
A hack at a slightly more general program that leaves your data intact.
*! 1.0.0 NJC Statalist 15 May 2008
program multibar
version 8
syntax varlist(numeric) [if] [in] [, VALues *]
marksample touse, novarlist
quietly {
count if `touse'
if r(N) == 0 error 2000
preserve
keep if `touse'
keep `varlist'
tempname stub lbl
local i = 1
foreach v of local varlist {
gen `stub'`i' = `v'
label def `lbl' `i' "`v'", add
local ++i
}
tempvar id
gen `id' = _n
reshape long `stub', i(`id')
label val _j `lbl'
contract `stub' _j, zero
}
if "`values'" != "" {
graph hbar (asis) _freq, over(_j) over(`stub') `options'
}
else graph hbar (asis) _freq, over(`stub') over(_j) `options'
end
That is a bit awkward, as in practice you might want to reach inside and
add suboptions to the -over()- options.
In many ways, the best strategy is
1. New structure first.
2. Then -graph-.
Hoping to do it all via one -graph- command is probably hoping for too
much.
Nick
[email protected]
Tunga Kantarci
I have a graphing question: I have 7 variables. All the variables take
values from 1 to 4.
I would like to produce a single graph on which the frequencies are
categorized for the seven variables, for each of the 4 values. That is,
for value one
depict a frequency bar for the first variable
depict a frequency bar for the second variable next to it
depict a frequency bar for the third variable next to it
for value two
depict a frequency bar for the first variable
depict a frequency bar for the second variable next to it
depict a frequency bar for the third variable next to it
for value three
depict a frequency bar for the first variable
depict a frequency bar for the second variable next to it
depict a frequency bar for the third variable next to it
for value four
depict a frequency bar for the first variable
depict a frequency bar for the second variable next to it
depict a frequency bar for the third variable next to it
Here the categorization is over "the values the seven variables take",
and
it is not over "a variable".
I tried several commands of bar graph but cannot really get what I want.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/