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]

Re: st: extraction and appending of data


From   Prakash Singh <[email protected]>
To   [email protected]
Subject   Re: st: extraction and appending of data
Date   Wed, 18 Apr 2012 11:35:13 +0530

Thanks Phil

Nick, I am sorry but I just thought that it will help to understand
the problem. In future, I will stick to your advice.



Thanks
Prakash
On Tue, Apr 17, 2012 at 6:38 PM, Nick Cox <[email protected]> wrote:
> Unless the datasets are enormous, you can -keep- the observations for
> -level==1- just once, in the final dataset. You don't (obviously) need
> to loop around the datasets twice.
>
> A presentation detail, but a troubling one for people who don't know
> your data, is that you seemingly have a variable -level- and a local
> macro -level- that aren't related. That is perfectly legal, but it
> makes understanding your code just that bit harder.
>
> Statalist can be tough: you get an opportunity to state your problem,
> but if it's too difficult to understand, it will just get deleted.
> Nobody is obliged to answer anything. Maximizing clarity is really
> important.
>
> Nick
>
> On Tue, Apr 17, 2012 at 1:37 PM, Prakash Singh <[email protected]> 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/

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