[Stata] Append files using loop

#1
Hi,

I have about 20 files and I need to append 2 of them over and over.
Meaning append file0 to file1 and file1 to file2 and so on...
I wish to write a short loop code that will append each file to the next one.

I tried this-
forv y=0/10 {
use file`y', clear
append using file`y'+1
save file`y'new.dta
}
It didn't work and I don't really know how to fix it.

I thought about another code that will run but it's just wrong.

forv y=0/7 {
g x=`y'+1
forv x=1/8 {
use file`y', clear
append using file`x'
save file`y'new.dta, replace
}

Any ideas?
Help would be much appreciated
 

Dason

Ambassador to the humans
#2
I don't know how to do what you want in STATA (never used it). But if you still haven't figured this out I could offer up some code to do it in R.
 
#3
Hey there,

I think that this might work:

forv y=0/10 {
local k = `y' + 1
use file`y', clear
append using file`k'
save file`y'new, replace
}

Hope this helps!

Etienne
 
#5
I don't know how to do what you want in STATA (never used it). But if you still haven't figured this out I could offer up some code to do it in R.
I'm not very familiar with R and I think my work has some security issues with me downloading programs so I probably won't be able to use it.
Thank anyways