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 11:18:39 -0500

Hi Nick

Thanks a lot.
The command ds3 works perfectly.

Best.




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




[email protected]
>
> 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.

If a variable label ending in "NA" means that
the variable is of no use, then you
can use -ds3- from SSC to drop such variables.

ds3, has(varl *NA)
drop `r(varlist)'

Alternatively, here is the route from first
principles.

foreach v of var * {
             local label : variable label `v'
             if substr(`"`label'"',-2,2) == "NA" {
                         drop `v'
             }
}

On the other hand, if the diagnostic is
just no non-missing values, then use
-dropmiss- as previously mentioned, or

foreach v of var * {
             capture assert missing(`v')
             if _rc == 0 {
                         drop `v'
             }
}

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