Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: STATA graph question: Combining Histograms


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: STATA graph question: Combining Histograms
Date   Thu, 18 Aug 2011 09:52:13 +0100

Christoph's commands should have one comma, not two. But I don't think
that is what is being sought here.

Here is another guess.

Assuming that the answers to different questions are in different
variables, you want a combined histogram across variables, and
-histogram- doesn't support that. Reach for a -reshape-, then. Given
some fake data

clear
set obs 100
forval i = 1/10 {
      gen q`i' = ceil(5 * runiform())
}

. ds
q1   q2   q3   q4   q5   q6   q7   q8   q9   q10

Marlis presumably already has an identifier, but I need one

. gen id  = _n

. reshape long q, i(id)
(note: j = 1 2 3 4 5 6 7 8 9 10)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                      100   ->    1000
Number of variables                  11   ->       3
j variable (10 values)                    ->   _j
xij variables:
                          q1 q2 ... q10   ->   q
-----------------------------------------------------------------------------

. rename _j question

. rename q answer

. histogram question, by(answer) discrete xla(1/10) freq

Nick

On Wed, Aug 17, 2011 at 10:26 PM, Christoph Engel <engel@coll.mpg.de> wrote:

> If all you want is 10 graphs in one line, the following would do
>
> hist response26, freq, by(group, cols(10))
>
> maybe together with
>
> hist response26, freq, by(group, cols(10)) xsize(10) ysize(2)
>
> If you also want to change the order, you need memory graphs. You could do
> the following
>
> forvalues i = 1/10 {
>    hist response26 if group == `i', freq title("group `i'") name(group`i',
> replace)
>    }
>
> and could then arrange them at will, using
>
> graph combine group2 group4 group6
>

> Am 17.08.2011 22:15, schrieb Marlis Gonzalez Fernandez:
>>
>> Nick-
>>
>> Excuse my naiveté... have not figured out all the rules yet.
>>
>> Yes I did:
>>
>> . histogram response26, freq
>>
>> and repeated for 10 different responses thus generating 10 different
>> histograms that I would like to combine (basically as they are) side by side
>> so people can visually compare the frequencies between questions. Not
>> worried about labeling at this point.
>>
>> Used:
>>
>> . graph combine graph1 graph2 graph3
>>
>> But that is not what I am looking for.
>>
 Nick Cox
>>
>> We can let -rep78- of the auto data serve as a Likert scale. (The term
>> Likert honours Rensis Likert.)
>>
>> Without code examples of what you tried what you want remains a bit
>> vague. Do you want axis scales? labels on the bars? or what?
>>
>> Is this what you want?
>>
>> . sysuse auto
>> (1978 Automobile Data)
>>
>> . histogram rep78, freq
>>
>> . tab rep78
>>
>>      Repair |
>> Record 1978 |      Freq.     Percent        Cum.
>> ------------+-----------------------------------
>>           1 |          2        2.90        2.90
>>           2 |          8       11.59       14.49
>>           3 |         30       43.48       57.97
>>           4 |         18       26.09       84.06
>>           5 |         11       15.94      100.00
>> ------------+-----------------------------------
>>       Total |         69      100.00
>>
>> . histogram rep78, freq discrete barw(0.8)  yaxis(1 2) yla(6.9 "10"
>> 13.8 "20" 20.7 "30" 27.6 "40" , axis(2)) ytitle("Percent", axis(2))
>>
>> Here I did it by mental arithmetic after noting that 69 is 100% and 6.9 is
>> 10%.
>>
>> Nick
>>
>> On Wed, Aug 17, 2011 at 8:19 PM, Marlis Gonzalez Fernandez
>> <mgonzal5@jhmi.edu>  wrote:
>>
>>> I am trying to combine frequency histograms for several questions into
>>> one graph.  Each variable has the answers to questions in a likert scale
>>> (always, frequently, infrequently, never, don't know).  I want to plot the
>>> frequency and percent for each question side by side.  Have not found a good
>>> way to do this.

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index