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 11:54:32 +0000
Nick:
> The second is that you are planning to create about 10,000 datasets
> with not much in them. I would instead create a list of names of empty
> datasets in a local macro, and then with that create a composite
> dataset with the same stuff, all just once.
Thanks too.
I have already implemented Maarten's suggestion, but could you give exemplary code?
> An overarching question is why you need to pretend that empty datasets
> are populated, but I guess there is a good reason.
I do not pretend that they are populated, the values are in fact all zero.
In a first stage I calculated counts, but if Stata did not find anything to count it created an empty dataset.
Best,
Florian
-----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/