Hello,
I'm a student and new STATA user. I have 30 or so separate STATA .dta data files that are identically formatted. I hope to sum the values of just a single column in each data file ("Value" is the name of the column), and then concatenate those summed values into a vector. I hope to make a for loop to iterate through each of these 30 or so similar files (like a macro) and then string the values together.
The names of the .dta files are wtf62.dta, wtf63.dta, etc. corresponding to data for 1962-1999 in Desktop folder WTF Data.
I've tried the code below, but it returns an error with "invalid 62".
*sum global trade in given year, create composite timeseries vector "trade"
forvalues i = 62(1)99 {
use "/Users/simon/Desktop/WTF Data/wtf"`i'".dta"
forvalues j = 1(1)38 {
gen trade[`j',1] = sum(value) <---- is this indexing incorrect?
}
}
end
Do I need to somehow close the existing .dta file to access the next one? In which case, how do I retain summed values between data files?
Thanks so much for your time.
Sincerely,
Simon
I'm a student and new STATA user. I have 30 or so separate STATA .dta data files that are identically formatted. I hope to sum the values of just a single column in each data file ("Value" is the name of the column), and then concatenate those summed values into a vector. I hope to make a for loop to iterate through each of these 30 or so similar files (like a macro) and then string the values together.
The names of the .dta files are wtf62.dta, wtf63.dta, etc. corresponding to data for 1962-1999 in Desktop folder WTF Data.
I've tried the code below, but it returns an error with "invalid 62".
*sum global trade in given year, create composite timeseries vector "trade"
forvalues i = 62(1)99 {
use "/Users/simon/Desktop/WTF Data/wtf"`i'".dta"
forvalues j = 1(1)38 {
gen trade[`j',1] = sum(value) <---- is this indexing incorrect?
}
}
end
Do I need to somehow close the existing .dta file to access the next one? In which case, how do I retain summed values between data files?
Thanks so much for your time.
Sincerely,
Simon