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

Re: st: dropping variables


From   "Dimitriy V. Masterov" <dvmaster@lily.src.uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: dropping variables
Date   Wed, 17 Mar 2004 16:48:55 -0600 (CST)

There might be a more clever way of doing this, but here's my solution:

*********************************************************************************
/* This defines a local named variables that contains a list with all variables */
unab variables:  _all

/* This loop drops all variables that have fewer than 100 obs. */
foreach var in `variables' {
qui sum `var'
	if r(N)<100 {
		drop `var'
	}
}
*********************************************************************************

DVM

On Wed, 17 Mar 2004, Eric Uslaner wrote:

> Hi,
>
> I know of Nick Cox's great dropmiss program.  I want to do something
> akin to it (without having to drop each variable individually).  Say
> that a data set has N cases and I want to drop variables that have fewer
> than n nonmissing cases.  Theoretically I could generate new variables
> through count, but my data set is already close to the maximum allowed
> without upgrading to SE (which is why I want to drop some variables).
> Is there a way to do this:
>
> drop if _N < n
>
> or something similar?
>
> Thanks much,
>
> Ric Uslaner
> euslaner@gpvt.umd.edu
>
>
> *
> *   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/
>

_______________________________________________________________________________
Dimitriy V. Masterov

Work:
Center for Social Program Evaluation
1155 East 60th St. Room 038
Chicago, IL 60637
Work: (773)256-6005
Fax: (773)256-6313

Home:
1312 East 53rd St., Apt.309
Chicago, IL 60615
Mobile: (773)220-2760


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index