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

Re: st: RE: Removing variables with no observation from datasets


From   [email protected]
To   [email protected]
Subject   Re: st: RE: Removing variables with no observation from datasets
Date   Thu, 16 Jan 2003 10:28:01 -0500

Thanks Nick,

DHS are the Macro-International databases on Demographic and Health Surveys.
Many variables in these datasets contains missings observations and are
labelled with NA: I mean:
e.g:
- v224 "Child receives juice, NA"
-tab v224
. no observation

I want to know how to drop these variables.


Cheers.







                                                                                                                                                
                      "Nick Cox"                                                                                                                
                      <[email protected]>            To:      <[email protected]>                                               
                      Sent by:                          cc:                                                                                     
                      owner-statalist@hsphsun2.         Subject: st: RE: Removing variables with no observation from datasets                   
                      harvard.edu                                                                                                               
                                                                                                                                                
                                                                                                                                                
                      01/16/2003 09:41 AM                                                                                                       
                      Please respond to                                                                                                         
                      statalist                                                                                                                 
                                                                                                                                                
                                                                                                                                                
                                                                                                                                                
                                                                                                                                                




[email protected]
>
> I have a list of variables with a certain number of them
> labelled "...some label..., NA" (mostly DHS variables)
> where NA stands for Not Available.
>
> Since it is too hard to manually remove them, I would like
> to know if there exists a certain way to quickly drop them.
>

I am not clear on the details here:
in particular, I don't know what "DHS" means
and whether you mean _values_
when you say _labels_. But I think the
general problem is fairly clear.

There are various ways to approach it.

One which may apply is to decide that any
variable for which all values are identical is, in
essence, uninformative and can thus be
dropped.

Here is code for this. (Warning:
could be slow with very large data sets.)

foreach v of var * {
             sort `v'
             if `v'[1] == `v'[_N] {
                         drop `v'
             }
}

-dropmiss- (STB-60) is another solution,
but it depends on your following
Stata conventions on missing values.

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