Dear all,

I tried appending some files using the following codes. Both worked but there are some problems (Code 1 created many duplicates; Code 2- many missing values). I am wondering what could be the problem.


Any help would be appreciated.
Oyun

PHP Code:
Code 1:

cd "C:\PC\Results"

forval i 1/88 {
    
preserve
    import excel 
"C:\PC\Results\Results_copy.xlsx"sheet("Week `i'"firstrow clear
    save 
"C:\PC\Results\Results_copy_`i'.dta"replace
    restore
    sort idnum
    append using 
"C:\PC\Results\Results_copy_`i'.dta"force
    save 
"C:\PC\Results\Results_all'.dta"repalce
    rm 
"C:\PC\Results\Results_copy_`i'.dta"
            
}    

Code 2:

clear
tempfile building
save 
`building', emptyok

forval i = 1/88  {
    import excel "C:\PC\Results\Results_copy.xlsx", sheet("Week 
`i'") firstrow clear
    gen source = `"`i'"'
    display `"
Appending `i'"'
    append using 
`building'
    save `"`building'"', replace