Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Richard Goldstein <richgold@ix.netcom.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: tabstat upside down |

Date |
Wed, 27 Apr 2011 08:15:21 -0400 |

thanks for the various suggestions; I have what I wanted Rich On 4/26/11 6:40 PM, Nick Cox wrote: > Good suggestions. Here is another way. The first part just fabricates data. > > clear > set obs 100 > gen acuteall = runiform() > forval j = 1/30 { > local split = runiform() > gen e`j' = runiform() < `split' > } > > matrix averages = J(30,2,.) > forval j = 1/2 { > local J = `j' - 1 > forval i = 1/30 { > su acuteall if e`i' == `J', meanonly > matrix averages[`i', `j'] = r(mean) > } > } > mat colname averages = 0 1 > mat li averages, format(%4.3f) > > > On Tue, Apr 26, 2011 at 10:07 PM, Eric Booth <ebooth@ppri.tamu.edu> wrote: > >> I'm not sure I completely follow, but for a dataset that looks something like: >> *********************begin example >> clear >> set obs 1000 >> g acuteall = rbinomial(1, .4) >> forval n = 1/30 { >> g e`n' = rbinomial(1, .4) >> } >> sa "test.dta", replace >> **** >> /* >> you say you want a" summary comparing the mean acuteall for each category of each of e1 thru e30..." >> yet, e1-e30 are not categories. I interpret this to mean you want the mean of acuteall when e1 ==1 and >> then e2==1 and so on, like: >> */ >> su acuteall if e1==1 >> di "`r(mean)'" //notice this equals the first obs in the collapsed data below >> >> **but for all vars...so you could collapse like: >> g id = _n >> reshape long e, i(id) j(ee ) >> keep if e==1 >> collapse (mean) acuteall, by(ee) >> **to get the mean of acute all where e* == 1 >> **now, you can list, outsheet, texsave etc this dataset as a table >> >> >> **OR** >> ****** maybe you want something more like tabout(from SSC) has to offer(?): >> u test.dta, clear >> tabout e* using "test.txt", sum oneway /// >> replace c(mean acuteall) >> type "test.txt" >> >> tabout e* acuteall using "test2.txt", /// >> replace c(col) f(1p) >> type "test2.txt" >> ********************end example > > Richard Goldstein [richgold@ix.netcom.com] > >> 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/

**References**:**st: tabstat upside down***From:*Richard Goldstein <richgold@ix.netcom.com>

**st: RE: tabstat upside down***From:*Eric Booth <ebooth@ppri.tamu.edu>

**Re: st: RE: tabstat upside down***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: Re: Help stata** - Next by Date:
**Re: st: Problem with infix: record too long** - Previous by thread:
**Re: st: RE: tabstat upside down** - Next by thread:
**re: st: tabstat upside down** - Index(es):