Statalist The Stata Listserver


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

RE: Re: st: shorthand


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: Re: st: shorthand
Date   Mon, 5 Jun 2006 18:15:07 +0100

Austin is correct in one sense. 

"missing" and "numeric variable being ."
are not the same thing. 

However, if a string variable were caught up 
in varlist, the loop would fail at
the variable in question with a "type mismatch". 
The code would not behave as Austin implies, 
producing all zeros. 

I thought that was a feature when 
contemplating the code I proposed. That is, 
Timothy would find that a variable 
he thought was numeric was really
string, and so be advised of a misapprehension. 

In addition, Austin's code would catch .a ... .z 
as extended missing values. 

Only Timothy can say whether that is what he 
wants, is what he doesn't want, or is irrelevant
to the case. 

I was sticking rather literally to the original
question, and not trying to guess what he should
want, although I do follow the other strategy
on occasion. 

Nick 
[email protected] 

Austin Nichols
 
> Timothy Mak--
> If you wind up with logical==0 everywhere, you might have included a
> string variable in your varlist... try also
> 
> gen byte allmiss = 1
> ds a10*
> foreach v in `r(varlist)' {
>  qui replace allmiss = 0 if !mi(`v' )
>  }
> list if allmiss==1
> 
> but are you sure you want to list all variables in all observations
> where all a10* are missing?  You will be listing a lot of dots...
> maybe you want to
> 
> gen byte allmiss = 1
> qui ds
> local allvars `r(varlist)'
> qui ds a10*
> local avars `r(varlist)'
> local tolist: list allvars - avars
> foreach v of local avars {
>  qui replace allmiss = 0 if !mi(`v' )
>  }
> list `tolist' if allmiss==1
> 
> 
> On 6/5/06, n j cox <[email protected]> wrote:
> > This problem is no problem. Loop over
> > your varlist instead:
> >
> > gen byte logical = 1
> > quietly foreach v of var <varlist> {
> >         replace logical = 0 if `v' < .
> > }
> >
> > Nick
> > [email protected]
> >
> > Timothy Mak
> >
> > This is ok if my variables are a100, a101, a102, and so on, but it
> > wouldn't work if I have say a101a, a102a, a102b, a103_oth, 
> and so on,
> > variables that have the same root but don't have other 
> things in common...
> >
> > But thanks anyway.
> >
> > Dominic Muston
> >
> > I'm not sure this is shorter!
> >
> > gen logical==1
> > forvalues i=100(1)200 {
> >       replace logical = 0 if a`i'!=.
> > }
> > list if logical==1

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