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: tabstat upside down


From   "Airey, David C" <david.airey@vanderbilt.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   re: st: tabstat upside down
Date   Tue, 26 Apr 2011 16:47:21 -0500

.

One way is the use -postfile-. Another way must be to store the e(b) results of -mean x, over(var1)- to a growing matrix. I'd like to see how you do that in Stata using either Stata matrix or Mata, if someone can show us. I typically don't use matrices for housekeeping but should.

clear

tempname memhold
tempfile results
postfile `memhold' str5 varname mean1 mean0 using "`results'", replace

set obs 100
local step 3
forvalues i = 1/16 {
	generate var`i' = cond(runiform() < (`step'/100),1,0,.)
	local step = `step' + 3
}
rename var16 x


foreach var of varlist var1-var15 {
	summarize x if `var' == 1, meanonly
	local mean1 = r(mean)
	summarize x if `var' == 0, meanonly
	local mean0 = r(mean)
	post `memhold' ("`var'") (`mean1') (`mean0')
}

postclose `memhold'
use "`results'", clear

list


> all,
> 
> I have 30 binary variables (e1-e30) and I have another yes/no (0/1)
> variable called acuteall; I want to supply my client with an easy to
> follow summary comparing the mean acuteall for each category of each of
> e1 thru e30; -tabstat-, however, supplies me with the mean of each of e1
> thru e30 for each category of acuteall (command: -tabstat e1-e30,
> by(acuteall)-)
> 
> in other words, in the following table, I want to see .122 v. .184 and
> what I get instead is .04 v. .0634; suggestions more than welcome (I
> could not see how to do this with -collapse- either, but maybe someone
> else can)
> 
> . ta e1 acuteall, ro co nofreq
> 
> +-------------------+
> | Key               |
> |-------------------|
> |  row percentage   |
> | column percentage |
> +-------------------+
> 
>            |  discharge to acute
> congestive | (no includes everyone
>      heart |        else)?
>    failure |         N          Y |     Total
> -----------+----------------------+----------
>          N |     87.80      12.20 |    100.00
>            |     96.00      93.66 |     95.71
> -----------+----------------------+----------
>          Y |     81.60      18.40 |    100.00
>            |      4.00       6.34 |      4.29
> -----------+----------------------+----------
>      Total |     87.53      12.47 |    100.00
>            |    100.00     100.00 |    100.00

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