[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Tabulating "missing" values |

Date |
Thu, 10 Apr 2003 11:06:16 +0100 |

Michael Oakes <oakes@epi.umn.edu> wrote: > > Hoping this isn't too obvious, but I cannot figure out > how to fill-in rows > > for response values that do not appear in my data but do exist > > hypothetically. > > > Imagine a variable, call it q5, that has possible > responses 1, 2, 3, and 4; > > let it be a simple Likert scale for example. The trouble > is if survey > > respondents only endorse/check values of 3 or 4, then my > table will look > > like this > > > . tab q5, nolab > > > | > > q5 | > > | Freq. Percent Cum. > > ------------+----------------------------------- > > 3 | 14 24.14 24.14 > > 4 | 44 75.86 100.00 > > ------------+----------------------------------- > > Total | 58 100.00 > > > But what I want is (something like) this, which I made > the "hard-way" via > > cut/paste > > > q5 | > > | Freq. Percent Cum. > > ------------+----------------------------------- > > 1 | 0 0.0 0.0 > > 2 | 0 0.0 0.0 > > 3 | 14 24.14 24.14 > > 4 | 44 75.86 100.00 > > ------------+----------------------------------- > > Total | 58 100.00 > > > In this example the hypothetical values of 1 and 2 are > represented, which is > > nice if I want to apply value labels and such for presentation. > > > I've looked at -tabcond- and a few other adaptations but > cannot find what I > > want -- I do not seem to understand -tabcond- if that > would do the trick. > > > Solutions? Shannon Driver > > Though this may not be the most elegant code, here is one > way to get the > results that I believe you want. I'm sure it could be > expanded to allow more > statistics and options. > > program tabrange < snip > > end > > Here are the results you get: > > . tabrange q5, range(1/4) > > +-------------------------------+ > | q5 Freq Percent Cum | > |-------------------------------| > | 1 0 0.00 0.00 | > | 2 0 0.00 0.00 | > | 3 14 24.14 24.14 | > | 4 44 75.86 100.00 | > |-------------------------------| > | Sum 58 100.00 | > +-------------------------------+ > > . tabrange q5, range(1 3 4 8) > > +-------------------------------+ > | q5 Freq Percent Cum | > |-------------------------------| > | 1 0 0.00 0.00 | > | 3 14 24.14 24.14 | > | 4 44 75.86 100.00 | > | 8 0 0.00 100.00 | > |-------------------------------| > | Sum 58 100.00 | > +-------------------------------+ > > . tabrange q5, range(14) > No observations for q5 in given range. -tabcond- (SSC) can be used to produce an awkward and indeed only partial solution for Michael's example, but only because the number of possible values contemplated is not more than 5. It is quite likely that that need not be true for real examples. -tabrange- from Shannon is a much better solution for of producing the results required. Note that -tabrange- could be a little slow for very large data sets. While it is still in an early stage, I'd like to float a possible name change. The connotations of "range" are strong here, and possibly misleading. Perhaps "values"? * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: Tabulating "missing" values***From:*sdriver@stata.com (Shannon Driver, StataCorp)

- Prev by Date:
**st: RE: -reshape-, or -by-?** - Next by Date:
**Re: st: text editors** - Previous by thread:
**Re: st: Tabulating "missing" values** - Next by thread:
**st: intraclass correlation** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |