Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: extraction and appending of data


From   Phil Clayton <philclayton@internode.on.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: extraction and appending of data
Date   Tue, 17 Apr 2012 08:47:17 -0400

If you read -help infle- you'll see that there's a clear option which bypasses the "you must start with an empty dataset" error.

It might be easier to use something like this:

tempfile mydata
foreach level of numlist 11/18 {
    infile using level`level'.dct, clear
    capture append using `mydata'
    save `mydata', replace
}
use `mydata', clear

Phil

On 17/04/2012, at 8:37 AM, Prakash Singh wrote:

> Dear stata listers
> I have following situation for which I am writing a stata programme
> code and I need all yours help in this. I have access to stata10.
> 
> I am working with National Sample Survey Organiation data of India.
> The data for single round and particular subject comes in number of
> txt files. The structure of the txt file is such that it contains a
> particular group of variables for certain states in one txt file. thus
> to get information for all the states for that particular group of
> variable we need to append the extracted data. Here the group which
> identifies variable identifier is level i.e. level1 has particular
> list of variables.
> 
> To put it in better way, suppose that whole data comes in 8 txt file
> and all the desired variables are divided into 10 levels, then we need
> to extract these 8 txt file for each level and append to get final
> data for individual level.
> The programme code which I have written in like this
> 
> local level "11 12 13 14 15 16 17 18"
> foreach l of local level {
> infile using level`l'.dct
> keep if level==1
> save "level`l'.dta", replace
> }
> local levels "12 13 14 15 16 17 18"
> foreach l of local levels {
> use "level1.dta", clear
> append using "level`l'.dta"
> save "level1.dta", replace
> }
> 
> Now the problem is that the code is only working for first txt file
> and after saving the level11.dta data whereas the outcome I was
> expecting is like level11.dta, ... level18.dta and then finally the
> appended level1.dta file.
> 
> stata gives this error
> you must start with an empty dataset
> r(18);
> 
> 
> 
> Thanks
> Prakash
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index