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: Variables loop and deletion under certain conditions
From
Nuno Soares <[email protected]>
To
[email protected]
Subject
st: Variables loop and deletion under certain conditions
Date
Thu, 12 May 2011 17:29:01 +0100
Hi everyone,
I'm having a problem regarding a data management task. I have several
.csv files that I need to import and treat in Stata. Each file has a
variable number of columns (which are variables) that cannot be
determined beforehand, and are imported into Stata as v1, v2, ...
Also, some of these variables/columns have no data which the database
from where they were extracted identifies with an #ERROR message in
line 5. What I need is to delete these variables when the error
message is present. I tried, without success, the following piece of
code:
foreach varname of varlist v*{
drop `varname' if `varname'[5]=="#ERROR"
}
However Stata returns the following error code:
invalid syntax
r(198);
Any ideas of why it isn't working? This should be straightforward, but
I can't understand why it isn't working...
Best wishes,
Nuno
*
* 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/