Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Seliger Florian" <seliger@kof.ethz.ch> |
To | "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |
Subject | st: Evaluate if a dataset is empty |
Date | Thu, 27 Mar 2014 10:51:57 +0000 |
Dear Statalist I want Stata to go through 20,000 small datasets (with a forvalues loop, datasets are indexed accordingly) and evaluate if the dataset is empty or not. About 50% of the datasets are empty meaning that there are no values for any variable. Please note that the variables are the same across all datasets. For empty datasets, Stata is asked to create observations, to generate an identifier and to set all values equal to zero (except for the identifier): set obs 18 bys id: replace id=_n forvalues k=1(1)18 { replace ind `k'=0 if ind`k'==. } At the end, I want to merge datasets based on "id". It is important that empty datasets are included and contain zeros. My problem is that I do not know how to ask STATA to evaluate whether a dataset is empty or not. Before "set obs 18" STATA does not recognize that values are missing meaning that there is simply "nothing" in the dataset. How can I ask STATA to identify that there is "nothing" within my loop (forvalues i=1(1).)? Thanks a lot, Florian * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/