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   Wed, 9 Feb 2011 00:56:42 +0000

Here is another way to do (part of) it. I borrowed the idea of using
-collapse- followed by -xpose- from Eric Booth.

*! 1.0.0 NJC 9 February 2011
program sumplot
	version 8.2
	syntax varlist(numeric) [if] [in] ///
	[, recast(str) oversubopts(str asis) *]

	marksample touse
	qui count if `touse'
	if r(N) == 0 error 2000

	preserve
	local nvars : word count `varlist'
	local i = 1
	foreach v of local varlist {
		local label`i' : var label `v'
		if `"`label`i''"' == "" local label `i' "`v'"
		local ++i
	}

	collapse (sum) `varlist' if `touse'
	xpose, clear

	tempvar which
	tempname what
	gen `which' = _n

	forval i = 1/`nvars' {
		label def `what' `i' `"`label`i''"', modify
	}

	label val `which' `what'

	if "`recast'" == "" local recast "hbar"
	graph `recast' v1, over(`which', `oversubopts') ///
	ytitle("") `options'
end

With the auto data, some dopey examples are

. sumplot foreign rep78

. sumplot foreign rep78, recast(bar)

. sumplot foreign rep78, recast(bar) oversubopts(sort(1) descending)

. sumplot foreign rep78, recast(bar) oversubopts(sort(1) descending)
blabel(total)

The program plots sums of numeric variables. The only non-standard
options are -recast()- and -oversubopts()-. The default is -hbar-; you
can -recast(bar)- or -recast(dot)-. The meaning of -oversubopts()-
should be clear from the help for -graph bar-.

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