Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: append to an empty dataset


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: append to an empty dataset
Date   Tue, 4 Nov 2008 12:56:08 -0500

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.
>
> Thank you,
>   Sergiy Radyakin
>
>>
>> **************
>> program append_empty
>> syntax using [, *]
>>
>> tempvar qwerty
>> gen `qwerty' = 1
>>
>> append `using', `options'
>> end
>> **************
>>
>> **************
>> clear
>> append_empty somedataset
>> **************
>>
>> Johannes
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index