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]

st: Variables loop and deletion under certain conditions


From   Nuno Soares <ndsoares@gmail.com>
To   statalist@hsphsun2.harvard.edu
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/


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