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   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Evaluate if a dataset is empty
Date   Thu, 27 Mar 2014 11:07:00 +0000

There are two parts. The first part is that you can find out remotely
that a dataset is empty by

describe using foo

and establishing whether r(N) == 0.

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.

An overarching question is why you need to pretend that empty datasets
are populated, but I guess there is a good reason.
Nick
[email protected]


On 27 March 2014 10:51, Seliger  Florian <[email protected]> wrote:
> 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/
*
*   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