Statalist The Stata Listserver

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

st: RE: Appending several files

From   "Newson, Roger B" <>
To   <>
Subject   st: RE: Appending several files
Date   Sun, 15 Oct 2006 13:29:54 +0100

You might use thwe -dsconcat- package, downloadable from SSC using the
-ssc- command. After installing, you can type

cd "C:\data"
qui fs *
dsconcat `r(files)'

and this should do the same job as your code. -dsconcat- also has a
-subset- option if you want to concatenate only subsets of the variables
and/or observations from each file.

I hope this helps.


Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
[] On Behalf Of Nuno Soares
Sent: 14 October 2006 12:43
Subject: st: Appending several files

Hi everyone,

I'm trying to make Stata to append several files that are in a given
directory without the need of specifying the name of each one. I was
thinking of doing something like this (using the fs package):

cd "C:\data"
qui fs *
foreach f in `r(files)' {
append using `f'

The problem with this code is that Stata doesn't allow to append a data
when it doesn't have a file opened (it will return the error message:
"no dataset in use

This means that I must have at least one of the files loaded in Stata
using the above code. But if I then use the above code, I would end up
getting duplicate observations, because the file I've first used is also
appended... Any ideas of how to solve this issue?



*   For searches and help try:

*   For searches and help try:

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