Bookmark and Share

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: collecting tabulate results


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: collecting tabulate results
Date   Tue, 8 Feb 2011 18:47:57 +0000

Here is another way to do it.

clear
set obs 100
local i = 1
foreach v in a b c d e f g h {
	gen `v' = runiform() < `i'/10
	local ++i
}

gen which = _n
gen count = .
local i = 1

qui foreach v in a b c d e f g h {
	count if `v' == 1
	replace count = r(N) in `i'
	label def which `i' "`v'", modify
	local ++i
}

label val which which
twoway bar count which if count < ., ///
barw(.6) xla(1/8, valuelabel) xtitle(services) ytitle(users)


On Tue, Feb 8, 2011 at 6:31 PM, Nick Cox <[email protected]> wrote:
> You can do this in Stata in various ways. Here is one.
>
> -tabm- from the -tab_chi- package on SSC has a  -replace- option that
> overwrites the data in memory with a dataset containing the data for
> this graph. In this script I create a small dataset and then push it
> through -tabm-. I just found out that -graph- does not like the name
> _values used by -tabm-, so I changed it.
>
> clear
> set obs 100
> local i = 1
> foreach v in a b c d e f g h {
>        gen `v' = runiform() < `i'/10
>        local ++i
> }
>
> tabm a-h, replace
>
> rename _values values
> label def values 0 no 1 yes
> label val values values
>
> graph bar (mean) values, over(_stack) ytitle(fraction using)
>
> Nick
>
> On Tue, Feb 8, 2011 at 5:46 PM, Broudy, David, DOH
> <[email protected]> wrote:
>
>> In a survey, we asked which hospital services respondents had used:
>> Dental
>> Diabetes
>> Mental Health...there are a total of 9 services
>> For each service, we asked a separate question with answers 1=yes, 0=no.
>> We would like to make a bar graph showing the number and percentage of "yes" responses for each service (variables are named N8A-N8I)
>>
>> Of course, I can  run tabulate nine times, record the number of "yes" answers to each question,  enter this into Excel, and use this to make the bar graph.
>>
>> Is there a way to collect the positive responses to a series of tabulates and use those with graph?
>>
>> When I do this manually, I make a file the looks like this:
>> Prgm, freq, pct, n
>> Dent,39, 30.7,127
>> DB,71,55.0,129
>> MH,106, 82.8,128...
>> Then:  graph bar freq, over(prgm, sort(1))  etc
>>
>> We have quite a number of questions formatted like this, so an alternative to doing it manually would be helpful.
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index