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

st: RE: Dropping variables


From   Zhiqiang Wang <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Dropping variables
Date   Thu, 4 Nov 2004 14:09:21 +1000

Try this: 

foreach var of varlist  soils* {
	sum `var'
 	if r(mean)==0 {
		drop `var' 
 	}
}

The -if- expression after -drop- is only for selecting a subset of
observations. 

Zhiqang Wang
Centre for Chronic Disease
School of Medicine 
The University of Queensland, Australia
 
From: Pradeep Kurukulasuriya [mailto:[email protected]] 
Sent: Thursday, 4 November 2004 1:42 PM
To: [email protected]
Subject: st: Dropping variables

I have  a large dataset with a lot of variables. I am trying to get rid of a
subset of the variables subject to a IF condition. I thought of  doing this
in a loop such as the following:

foreach var of varlist soils*{
sum `var'
drop `var' if r(mean)==0
}

However, the above doesn't work because stata doesn't like line 3. Is there
a way around this or another way to get rid of particular variables subject
to an IF condition?

Thanks
Pradeep





*
*   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