Statalist The Stata Listserver


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

Re: st: Re: Appending several files


From   "Frederick J. Boehmke" <boehmke@umich.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: Appending several files
Date   Mon, 16 Oct 2006 15:21:37 -0400 (EDT)

Or you could just use the emptyok option with save:

save filename, emptyok

which will save the file even without any observations.
Then append away.

On Mon, 16 Oct 2006, Jens Lauritsen wrote:

Date: Mon, 16 Oct 2006 18:25:06 +0200
From: Jens Lauritsen <jl@epidata.dk>
Reply-To: statalist@hsphsun2.harvard.edu
To: statalist@hsphsun2.harvard.edu
Subject: st: Re: Appending several files

A simple technique can be useful to "trick" Stata to behave like a dataset exists:
* create an empty dataset with one observation and one variable:
set obs 1
gen articifialvar = 1

* now you can do anything where Stata expects an open data set to be present, e.g. from
* the current discussion:
qui fs *
foreach f in `r(files)' {
append using `f'
}

* following appending all the files the first imaginary observation and variable can be dropped:
drop artificialvar
drop in 1

regards
Jens Lauritsen
Odense, Denmark

*
* 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/



                                                         - Fred

 Note updated contact info (from August 01, 2005 to August 01, 2007):

                               Frederick J. Boehmke
                     Associate Professor of Political Science
                           University of Iowa (on leave)
                                boehmke@umich.edu
          _-------------------------------------------------------------_
         <        Robert Wood Johnson Foundation Research Fellow         >
         <  University of Michigan               Office: M2232 (SPH II)  >
         <  School of Public Health              Phone:  734 764 2089    >
         <  Health Management and Policy         Fax:    734 936 9813    >
         <  109 Observatory, Room M2232          boehmke@umich.edu       >
         <_ Ann Arbor, MI  48109-2029                                   _>
           -------------------------------------------------------------
                          http://myweb.uiowa.edu/fboehmke
*
*   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