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: Evaluate if a dataset is empty
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Evaluate if a dataset is empty
Date
Thu, 27 Mar 2014 12:03:57 +0100
On Thu, Mar 27, 2014 at 11:51 AM, Seliger Florian wrote:
> 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.
capture assert _N == 0
if _rc == 0 {
set obs 18
...
}
The logic is that _N is the number of observations in the dataset, so
_N == 0 corresponds to an empty dataset. -assert- gives an error
message when the statement is values, but -capture- captures these
error messages and leaves the return code behind in _rc. No error
message corresponds with an return code 0, so _rc == 0 corresponds
with an empty dataset.
Hope this helps,
Maarten
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* 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/