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 |
Phil Schumm <pschumm@uchicago.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: "table" showing summary of ~100 ternary variables? |

Date |
Sat, 30 Oct 2010 15:13:47 -0500 |

On Oct 30, 2010, at 12:40 PM, Michael Costello wrote:

I have about 100 ternary variables (0=incorrect, 1=correct, 2=NoResponse, .=Missing) and I would like to get a table of theresponses that looks like this:------------------------------------------------------- | | Correct Incorrect No Response . ----------+-------------------------------------------- Var1 | 2 21 4 21 Var2 | 8 19 13 18 Var3 | 30 19 4 19 Var4 | 18 21 47 22 Var5 | 11 27 8 30Maybe I'd even like to add in a proportion of correct or ratio ofcorrect to incorrect into the table.Is there a function to do this or something reasonable similar?

set obs 100 gen id = _n lab def mylab 1 "Correct" 2 "Incorrect" 3 "No response" 4 "Missing" set seed 123456789 forv i = 1/5 { gen byte y`i' = cond(runiform()<0.95, ceil(runiform()*3), 4) lab val y`i' mylab } replace y5 = 2 if y5==1

Now, the first trick is to reshape your data into long form: reshape long y, i(id) j(Var)

set obs `=c(N) + 1' replace y = 5 if _n == _N lab def mylab 5 "Prop. correct", add

fillin Var y collapse (count) cnt=id, by(Var y)

egen correct = max((y==1)*cnt), by(Var) egen nonmiss = sum(inlist(y,1,2,3)*cnt), by(Var) bys Var (y): replace cnt = correct[1] / nonmiss[1] if y == 5 And finally, we can use -tabdisp- to create our table: . tabdisp Var y if !mi(Var), c(cnt) format(%9.2g)

| y

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

**Follow-Ups**:**RE: st: "table" showing summary of ~100 ternary variables?***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: "table" showing summary of ~100 ternary variables?***From:*Phil Schumm <pschumm@uchicago.edu>

**References**:**st: "table" showing summary of ~100 ternary variables?***From:*Michael Costello <michaelavcostello@gmail.com>

- Prev by Date:
**Re: st: R: death rate calculation - (flag: Stata 9/2 SE)** - Next by Date:
**re: Re: Re: st: gaps in the Hodrick-Prescott filter** - Previous by thread:
**st: "table" showing summary of ~100 ternary variables?** - Next by thread:
**Re: st: "table" showing summary of ~100 ternary variables?** - Index(es):