Statalist


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

Re: st: RE: combining many data files


From   "Mingfeng Lin" <[email protected]>
To   [email protected]
Subject   Re: st: RE: combining many data files
Date   Wed, 19 Nov 2008 22:16:23 -0500

Thank you Matt - this works great too.  I appreciate the tip.  For
renaming files (as Kyle mentioned), I just remembered a trick to
rename a large number of files simultaneously on Windows (at least on
XP): select all files you want to rename, then, with cursor pointed at
the first file (all other files still selected), right click and
choose "rename".  Then type in something like
file(1).dta

and you'll see all other files renamed into file(2).dta, file(3).dta
etc. But it only works on Windows - for Mac users the extended
function could be the only way out. The extended function is also
likely to work well when we just want some of these files.


Thanks again to both of you!

Mingfeng

On Wed, Nov 19, 2008 at 9:53 PM, Matt Spittal
<[email protected]> wrote:
> Mingfeng,
>
> I'm a big fan of using -foreach- for these types of problems.  The first thing is to make sure that your datasets are named in a similar way.  In the example below I have used a set of datasets called data1, data2, ..., data30.  Once that is done, you can place your -append- command inside a -foreach- loop. For instance:
>
>        use data1, clear
>        foreach num of numlist 2/30 {
>                append using data`num'
>        }
>
> This code is really just a shortcut for the following:
>
>        use data1, clear
>        append using data2
>        append using data3
>        ...
>        append using data30
>
> Other variations are possible too, see -help foreach-.
>
> -- Matt
> [email protected]
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Mingfeng Lin
> Sent: Thursday, 20 November 2008 1:35 PM
> To: [email protected]
> Subject: st: combining many data files
>
>
> Greetings!
>
> I am wondering if there's a straightforward way to append a large
> number of .dta files into one file using Stata? The -append- command
> seems to disallow wildcards in the file names.  I do find one method
> from UCLA's ATS website,
>
> http://www.ats.ucla.edu/stat/stata/faq/append_many_files.htm
>
> but I'm still hoping there's an easier way, or somehow getting the
> -append- command to recognize the wildcards - so that I could just
> simply type
>
> append using *.dta
>
> Thanks :)
>
> Mingfeng
> *
> *   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/
>
> *
> *   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/
>
*
*   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