Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: append, empty?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: append, empty?
Date   Wed, 5 Jul 2006 17:51:25 +0100

I don't have a view on changing -append-, except that
this example doesn't persuade, given that an 
alternative is to take the first 
operation out of the loop, where it is at best 
uncomfortable and at worst inappropriate. 

use file1, clear
check_program 1 

forval x = 2/100 {
	append using file`x' 
	check_program `x' 
} 

where naturally check_program needs
to be written or replaced by other code. 

Your main issue seems to be upstream of 
all this, getting a list of files. Check 
out macrolists and -fs- from SSC, or tell
us why you do not know what the files are. 

The use of -forval- here clearly hinges 
on your files being numbered systematically.
Using -foreach- is naturally a much more
general alternative.

Nick 
n.j.cox@durham.ac.uk 

Jeph Herrin
 
> This is not a question, just a request concerning a minor
> nusiance, though there may be a solution I don't see.
> 
> I often have to patch together a large number of files with
> identical format, but check for errors that depend on the file
> index after appending each. Currently, the best way I can find
> to do this is, eg,
> 
> 
>    forv x=1/100 {
>  	if `x'==1 {
>  		use file1, clear
>  	}
>  	else {
>  		append using file`x'
>  	}
>           [check things depending on `x']
>    }
> 
> However, sometimes I don't know what the first file number is - or the
> intervening file numbers - so I have to trap this. It gets very messy.
> Ideally, -append- would have an "empty" option, so that  if 
> there is no
> dataset, -append- would -use-. Then I could just code
> 
>    clear
>    forv x=1/100 {
>           capture append using file`x', empty
>           [check things depending on `x']
>    }
> 
> 
> See how much cleaner? Is there a logical reason why this 
> would not work?
> I don't see how it would but any existing data at risk. Or is there a
> better way?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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