A test of whether there are no variables in memory is
if c(k) == 0 {
<stuff>
}
That way, you need not try to run a command and -capture- any failure.
Nick
[email protected]
Austin Nichols
e.g. just save the following to appemptyok.ado in your sysdir path:
prog appemptyok
syntax using [, *]
cap append `using', `options'
if _rc==3 {
tempvar x
g `x'=.
append `using', `options'
}
else if _rc!=0 error _rc
end
On Tue, Nov 4, 2008 at 12:41 PM, Sergiy Radyakin
<[email protected]> wrote:
> On Tue, Nov 4, 2008 at 9:05 AM, Johannes Geyer <[email protected]> wrote:
>> I had/have that problem too and most often I have to create a cycle
and an
>> exception (the first data set). Reading throught your posts I thought
why
>> not add that option -gen tempvar- to append when using it?
>>
>> Wouldn't that suffice?:
>
> Yes, and the program can be further improved to check if there are
> variables already present, and generate tempvar only for the empty
> dataset (because currently it will generate tempvar 100 times for 100
> datasets, and only 1 is required). It can also brunch inside to use or
> append depending on whether there is anything in memory. In any case
> this special treatment of the first dataset is a very unnecessary
> effort, which could have been easily avoided.
>
>
>>
>> **************
>> program append_empty
>> syntax using [, *]
>>
>> tempvar qwerty
>> gen `qwerty' = 1
>>
>> append `using', `options'
>> end
>> **************
>>
>> **************
>> clear
>> append_empty somedataset
>> **************
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/