Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Variables loop and deletion under certain conditions

From   Nuno Soares <>
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

foreach varname of varlist v*{
	drop `varname' if `varname'[5]=="#ERROR"

However Stata returns the following error code:

invalid syntax

Any ideas of why it isn't working? This should be straightforward, but
I can't understand why it isn't working...

Best wishes,

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index