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: RE: Problem in appending data files.


From   Amir Kasaeian <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: RE: Problem in appending data files.
Date   Tue, 6 Nov 2012 06:47:05 -0800 (PST)

Dear Friend,
bunch of thanks,
Amir
 
Amir Kasaeian, 
PhD Student in Biostatistics,
Dept. of Epidemiology and Biostatistics,
School of Public Health,
Tehran University of Medical Sciences (TUMS).
P.B. : 14155-6446
Cell Phone: +98-912-2063511
E-mail: [email protected]
            [email protected]   



----- Original Message -----
From: "MacLennan, Graeme" <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Tuesday, 6 November 2012, 17:37
Subject: st: RE: Problem in appending data files.

**** example begins ****
use S0, clear
gen Province = 0
forvalues i= 1/29 {
append using "C:\Total85\S`i'.dta" ,
replace Province=`i' if Province == .
}
save "C:\Total85\Total.dta", replace
**** example ends ****

HTH, g.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Amir Kasaeian
Sent: 06 November 2012 13:46
To: [email protected]
Subject: st: Problem in appending data files.

Dear all,
Good day!
I have a problem in appending my data files.
I wrote a loop but there is little problem that I don't know how to resolve it.
Your help will be appreciated.
I use stata MP 11.
The problem is that I have 30 files in a folder named S0 through S1. I want to have a final file named for example "Total" including a new variable as an indicator for observations of each of 30 separate files.
I wrote my file as :

forvalues i= 0/29 {
append using "C:\Total85\S`i'.dta" ,
gen Province=`i'
save "C:\Total85\Total.dta", replace
}


but the code stops at the first step alarming:


. do "C:\Users\AK\AppData\Local\Temp\STD00000000.tmp"

. forvalues i= 0/29 {
  2. append using "C:\Total85\S`i'.dta" ,
  3. gen Province=`i'
  4. save "C:\Total85\Total.dta", replace
  5. }
file C:\Total85\Total.dta saved
Province already defined
r(110);

end of do-file

r(110);


The Total file just includes observation from the S0.
Would you please help me to modify my codes?
Bunch of thanks,
Amir

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/faqs/resources/statalist-faq/http://www.ats.ucla.edu/stat/stata/


The University of Aberdeen is a charity registered in Scotland, No SC013683.

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://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/


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