Bookmark and Share

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]

Re: st: Interruption of a loop because of missing variables


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: Interruption of a loop because of missing variables
Date   Fri, 19 Nov 2010 15:17:37 -0600

you can -capture confirm variable cit_1- and use the return code to
see if you want to -continue-.

On Fri, Nov 19, 2010 at 1:25 PM, Florian Seliger <[email protected]> wrote:
> Dear Statalist,
>
> I want to run a foreach loop for 250 files. There are some files were  variables are missing so that the loop is interrupted.
>
> I have already tried to use the capture command, but I haven't found an adequate specification yet.
>
> Please see the following example:
>
> foreach file in acer.dta adobe.dta affiliated.dta ... {
>
> use "`file'"
>
> keep id cit_*
> reshape long cit_, i(id)
> drop if cit_ == ""
> drop _j
> ren cit_ pat_no
>
> save "sic_`file'", replace
> }
>
> ***end of the example***
>
> Generally, I have multiple cit_* variables in each dataset. The number is varying among the files. For some datasets, I may have 100 cit_* variables (cit_1, cit_2, ..., cit_100), but for others zero.
>
> How can I tell STATA that the commands should not be executed when there are zero cit_* variables and that I want STATA to proceed with the next file in this case?
>
> Thank you very much,
> Florian
>
>
>
>
>
> --
> GMX DSL Doppel-Flat ab 19,99 &euro;/mtl.! Jetzt auch mit
> gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
> *
> *   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/
>



-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index