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: One-way table and multiple variables
From
Kingsley Wong <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: One-way table and multiple variables
Date
Thu, 25 Aug 2011 07:31:18 +0000
Thanks Nick and Eric. I will give them a go.
Kind Regards,
Kingsley
________________________________________
From: [email protected] [[email protected]] on behalf of Nick Cox [[email protected]]
Sent: Thursday, 25 August 2011 2:40 PM
To: [email protected]
Subject: Re: st: One-way table and multiple variables
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
[email protected]
On Thu, Aug 25, 2011 at 4:35 AM, Eric Booth <[email protected]> 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/
*
* 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/