Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: programatically dropping variables that don't actually vary


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: programatically dropping variables that don't actually vary
Date   Thu, 9 Aug 2012 19:58:25 +0100

-findname- (SJ) may be useful here.

findname, all(@ == 0)

finds (numeric) variables all of which are equal to 0. If missings are
possible,

findname, all(@ == 0 | missing(@))

would be appropriate.

Nick

On Thu, Aug 9, 2012 at 7:46 PM, Earl, Jennifer Suzanne -
(jenniferearl) <jenniferearl@email.arizona.edu> wrote:

> I am working with a large number of dummy variables and using collapse to create derivative datasets that are the frequencies of 1's for each dummy variable (a couple of hundred through foreach loops). I want to drop any of the dummy variables that never had a 1 (so mean(dummy1)==0, or max(dummy)==0) but it seems that drop only lets you use an if statement to drop observations, but not an if statement to drop variables.
>
> My best guess is to use a list means to create a list of the variable names that can be stored in a local and then fed into a drop command, but can't seem to make that work either since I only want the list of variable names that have a mean of 0. Or maybe transpose the dataset, drop then since the variables are now observations, and transpose back? Another solution would be save through StatTansfer and use it's drop constants feature, and then bring the data back in, but there must be an easier way.
>
> Any ideas?
>
> Cheers,
>
> Jenn
>
> ***********************************
> Jennifer Earl
> Professor of Sociology
> Social Sciences 421
> University of Arizona
> Tucson, AZ 85721-0027
>
> Phone: (520) 621-3296
> ***********************************
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index