Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Dropping variables with mostly missing values again


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Dropping variables with mostly missing values again
Date   Sat, 8 Feb 2014 09:27:13 +0000

Not the way to do it. It's just

npresent, min(20)
keep `r(varlist)'

Example:

. sysuse auto
(1978 Automobile Data)

. gen useless = .
(74 missing values generated)

. gen justasuseless = ""
(74 missing values generated)

. npresent, min(20)

make               74
price              74
mpg                74
rep78              69
headroom           74
trunk              74
weight             74
length             74
turn               74
displacement       74
gear_ratio         74
foreign            74

. keep `r(varlist)'

. ds
make          mpg           headroom      weight        turn          gear_ratio
price         rep78         trunk         length        displacement  foreign

-useless- and -justasuseless- have gone.

Nick
[email protected]


On 8 February 2014 02:00, Eric M. Uslaner <[email protected]> wrote:
> Thanks to Rich, Amirsa, Jeph, and Nick.  It is likely my ignorance but I can't get this resolved.  For the solutions of Rich, Amirsa, and Jeph, I get all missing values.  For Nick's suggestion, I have:
>
> foreach V of varlist elecprod1750-visitorrooms2003 {
>         npresent,min(20)
>         keep `r(`V')'
> }
>
> And I see the npresent results as he suggested.  But the do file  I constructed above after the last variable leads to:
>
> varlist or in range required
> r(100);
>
> end of do-file
>
> r(100);
>
> And no values are changed.  What, please, am I doing wrong?  Thanks.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index