Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: help w/counting missing


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: RE: help w/counting missing
Date   Thu, 16 Oct 2003 14:10:00 -0400

Thank you Nick (except, of course, that I feel
a bit stupid for not having come up with one of
these -- esp. since I have used -ds- for similar
kinds of things in the past)

Rich

Nick Cox wrote:
> 
> Richard Goldstein
> >
> > I am trying to count, within each observation, across
> > a set of variables (about 190 of them), the number of
> > times a particular type of missing occurs (denoted
> > .b for numeric variables and "888888" for string variables).
> > Note that the set of variables includes both numeric and
> > string variables (and I would strongly prefer not to
> > separately list them in two statements using Nick Cox's
> > -rcount- if I don't have to).
> 
> I'd avoid that too if I were me. However, I can't
> see how to avoid some bifurcation of code to
> cope with these distinct cases. How about
> 
> gen mymiss = 0
> 
> foreach v of var <myvarlist> {
>         cap replace mymiss = mymiss + (`v' == "888888")
>         cap replace mymiss = mymiss + (`v' == .b)
> }
> 
> OR
> 
> gen mymiss = 0
> ds, has(type numeric)
> foreach v of var `r(varlist)' {
>         replace mymiss = mymiss + (`v' == .b)
> }
> ds, has(type string)
> foreach v of var `r(varlist)' {
>         replace mymiss = mymiss + (`v' == "888888")
> }
> 
> Nick
> [email protected]
> 
> *
> *   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/
*
*   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/



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