Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Prakash Singh <prakashbhu@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: extracting of data |
Date | Wed, 23 Jan 2013 21:33:40 +0530 |
Thanks a lot Prakash On Wed, Jan 23, 2013 at 8:02 PM, Jeph Herrin <stata@spandrel.net> wrote: > As Nick says, there is still some mystery about what you are doing. But > working off my previous guess, it looks like I made a mistake. The error > refers to trying to save your temporary file when it already exists; you > will need the two corrections //commented below: > > > clear > set more off > set mem 500m > tempfile mydata > forv l=1/9 { > clear // CLEAR data > save `mydata', emptyok replace // <-REPLACE > > forv d=1/9 { > infile using D:\TEAM_PC\level`l'\level`d'.dct, clear > capture append using `mydata' > save `mydata', replace > } > keep if level==`l' > save "D:\TEAM_PC\level`l'_list.dta", replace > } > > cheers, > J > > > > On 1/22/2013 11:58 PM, Prakash Singh wrote: >> >> Jeph thanks for the kind help. >> There seems to be small problem, if you could lighten a bit more then >> I think I am through. >> >> Though the loop is reading all the dct file within level but in the >> end it gives error massage >> >> file D:\TEAM_PC\level1_list.dta saved >> file C:\Users\Prakash\AppData\Local\Temp\ST_00000003.tmp already exists >> r(602); >> >> Prakash >> >> >> On Tue, Jan 22, 2013 at 11:49 PM, Jeph Herrin <stata@spandrel.net> wrote: >>> >>> Do you have 9 different .dct files for each level? Then maybe you intend >>> something like this: >>> >>> >>> clear >>> set more off >>> set mem 500m >>> tempfile mydata >>> forv l=1/9 { >>> save `mydata', emptyok >>> forv d=1/9 { >>> infile using D:\TEAM_PC\level`l'\level`d'.dct, clear >>> >>> capture append using `mydata' >>> save `mydata', replace >>> } >>> keep if level==`l' >>> save "D:\TEAM_PC\level`l'_list.dta", replace >>> } >>> >>> hth, >>> Jeph >>> >>> >>> On 1/21/2013 1:15 PM, Prakash Singh wrote: >>>> >>>> >>>> Nick >>>> Though I managed to write the code and run it but I realised today >>>> that for each level stata is extracting data from only one txt file. >>>> which means that only one dct file is being read. >>>> >>>> here is the revised code >>>> >>>> clear >>>> set more off >>>> set mem 500m >>>> tempfile mydata >>>> forv l=1/9 { >>>> infile using D:\TEAM_PC\level`l'\level`l'.dct, clear >>>> capture append using `mydata' >>>> save `mydata', replace >>>> keep if level==`l' >>>> save "D:\TEAM_PC\level`l'_list.dta", replace >>>> } >>>> >>>> >>>> Regards >>>> Prakash >>>> >>>> On Tue, Jan 1, 2013 at 9:32 PM, Prakash Singh <prakashbhu@gmail.com> >>>> wrote: >>>>> >>>>> >>>>> Thanks Nick >>>>> I got it finally >>>>> >>>>> Best wishes to all stata listers for 2013 >>>>> >>>>> Regards >>>>> Prakash >>>>> >>>>> On Mon, Dec 31, 2012 at 11:10 PM, Nick Cox <njcoxstata@gmail.com> >>>>> wrote: >>>>>> >>>>>> >>>>>> I don't understand what is holding you up. Your code shows that you >>>>>> are familiar with -foreach- and -forval-. So you need to write another >>>>>> big loop using that construct. >>>>>> >>>>>> Nick >>>>>> >>>>>> On Mon, Dec 31, 2012 at 4:37 PM, Prakash Singh <prakashbhu@gmail.com> >>>>>> wrote: >>>>>>> >>>>>>> >>>>>>> Nick, I thanked you for that >>>>>>> >>>>>>> I mentioned in the first mail that the structure of the data is such >>>>>>> that to have final data I need to extract 9 (using 9 dct file for >>>>>>> each >>>>>>> level) different level files then some of them I need to reshape and >>>>>>> then merge them. >>>>>>> >>>>>>> >>>>>>> Hope, I have made my query more clear to you. >>>>>>> >>>>>>> regards >>>>>>> Prakash >>>>>>> On Mon, Dec 31, 2012 at 9:48 PM, Nick Cox <njcoxstata@gmail.com> >>>>>>> wrote: >>>>>>>> >>>>>>>> >>>>>>>> You don't comment on my replacement of 9 lines of code with 1. >>>>>>>> >>>>>>>> Your main loop looks like another -forval- or -foreach- loop but you >>>>>>>> don't explain why you want to save different levels in different >>>>>>>> datasets. >>>>>>>> >>>>>>>> Nick >>>>>>>> >>>>>>>> On Mon, Dec 31, 2012 at 2:27 PM, Prakash Singh >>>>>>>> <prakashbhu@gmail.com> >>>>>>>> wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> Nick sorry but that is type error. >>>>>>>>> Thanks for the suggestion anyway. >>>>>>>>> >>>>>>>>> Moreover I am looking some help on creating look so that I can >>>>>>>>> repeat >>>>>>>>> the following code for each level 1 to 9. >>>>>>>>> >>>>>>>>> clear >>>>>>>>> set more off >>>>>>>>> set mem 500m >>>>>>>>> tempfile mydata >>>>>>>>> foreach l of numlist 11/19 { >>>>>>>>> infile using D:\TEAM_PC\level`l'.dct, clear >>>>>>>>> capture append using `mydata' >>>>>>>>> save `mydata', replace >>>>>>>>> } >>>>>>>>> use `mydata', clear >>>>>>>>> keep if level==1 >>>>>>>>> save level1_list.dta", replace >>>>>> >>>>>> >>>>>> * >>>>>> * For searches and help try: >>>>>> * http://www.stata.com/help.cgi?search >>>>>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/