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]
st: RE: Variables loop and deletion under certain conditions
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: Variables loop and deletion under certain conditions
Date
Thu, 12 May 2011 18:22:05 +0100
Indeed. No numeric variable can have a value "#ERROR". So, you could catch the string variables before with -ds- or -findname- (SSC).
Nick
[email protected]
daniel klein
Eric already answerd the "why" it does not work. The solution proposed
by Chris should work. Erics solution (although it is more an example)
can be modified, because it will fail if the loop contains numeric
variables. I do not know whether skipping numeric variables will
additionally saves some execution time.
---code revised---
foreach varname of varlist v*{
cap conf str v `v'
if _rc continue
if `varname'[5]=="#ERROR" drop `varname'
}
---end---
*
* 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/