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: Evaluate if a dataset is empty


From   "Seliger Florian" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Evaluate if a dataset is empty
Date   Thu, 27 Mar 2014 12:01:12 +0000

Thank you Maarten!! It works with my files.


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Maarten Buis
Sent: Donnerstag, 27. März 2014 12:04
To: [email protected]
Subject: Re: st: Evaluate if a dataset is empty

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/

*
*   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/


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