I am trying to set a condition within a nested loop. Now, the loop opens some folders; the condition is that if a folder has less than 50 files, than the iteration of the loop should be run. If it has more than 50 files, the iteration should be skipped. I tried to use -if- -else- and -continue- but I am doing something wrong: when a folder has >50 files, the loop is exited with no error produced.
It is the first time I find myself having to use -if- this way, apologies if the question is trivial.
Code:
clear local com_list `"`r(folders)'"' local years 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 foreach c of local com_list{ foreach y of local years{ clear cap n cd "C:/bilanci_unzip/`c'/csv/`c'/`y'" fs * *if elements of `r(files)' are >50, skip append loop local count_values_num: word count `com_list' di "Number of numeric values: `count_values_num'" if `count_values_num'<50 { foreach f in `r(files)'{ append using `"`f'"' *this is for having all the right info in labels3 replace labels3 = labels2 if labels3=="" } //close 'files' loop *save one file for each comune cd "C:/bilanci_unzip/`c'/csv/`c'/" save "`c'_`y'", replace } else{ continue } } //close 'year' loop } //close 'comune' loop log close
0 Response to if else conditional of number of elements in a local
Post a Comment