Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: One-way table and multiple variables |
Date | Thu, 25 Aug 2011 07:40:16 +0100 |
You can do this directly with -tabm- from -tab_chi- (SSC). . set obs 1000 obs was 0, now 1000 . forval j = 1/5 { 2. gen y`j' = ceil(`j' * runiform()) 3. } . tabm y* | values variable | 1 2 3 4 5 | Total -----------+-------------------------------------------------------+---------- y1 | 1,000 0 0 0 0 | 1,000 y2 | 491 509 0 0 0 | 1,000 y3 | 326 334 340 0 0 | 1,000 y4 | 254 248 249 249 0 | 1,000 y5 | 199 203 210 194 194 | 1,000 -----------+-------------------------------------------------------+---------- Total | 2,270 1,294 799 443 194 | 5,000 . tabm y*, transpose | variable values | y1 y2 y3 y4 y5 | Total -----------+-------------------------------------------------------+---------- 1 | 1,000 491 326 254 199 | 2,270 2 | 0 509 334 248 203 | 1,294 3 | 0 0 340 249 210 | 799 4 | 0 0 0 249 194 | 443 5 | 0 0 0 0 194 | 194 -----------+-------------------------------------------------------+---------- Total | 1,000 1,000 1,000 1,000 1,000 | 5,000 Also, -search multiple responses- in Stata. Nick n.j.cox@durham.ac.uk On Thu, Aug 25, 2011 at 4:35 AM, Eric Booth <ebooth@ppri.tamu.edu> wrote: > I'd start with -table- , or use a combination of -collapse- and some command to export your table (e.g., -outsheet- or Stata 12's - export excel-) For example: > > ******* > sysuse auto, clear > > **table** > table rep78, center c(n price n mpg n headr) > table rep78, center c(n price n mpg n headr) by(for) > > > **collapse & export** > preserve > collapse (count) price mpg headr, by(rep78) > lab var price "Freq Price" > lab var mpg "Freq MPG" > lab var headroom "Freq Headr" > > *export* > outsheet using "test", replace > **or** > if "`c(version)'" == "12" export excel using "test2.xlsx", /// > replace sheet("My Tables") firstrow(varl) > restore > ******** > > Also, you can take advantage of the formatting and exporting features of some user-written table commands like -tabout- or -outreg2- from SSC. -findit table- shows many possibilities. On Aug 24, 2011, at 10:13 PM, Kingsley Wong wrote: >> I am trying to create a table that shows the variables, variable values and frequencies in the following format: >> >> var1 var2 var3 >> value1 freq freq freq >> value2 freq freq freq >> ... >> >> All variables have the same set of values. >> >> I have tried -tab1- but it only creates one-way frequency table for each variable. Also, I have searched SSC but couldn't find a solution that suits my need. * * 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/