Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: extraction and appending of data


From   Prakash Singh <[email protected]>
To   statalist <[email protected]>
Subject   st: extraction and appending of data
Date   Tue, 17 Apr 2012 18:07:33 +0530

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index