Hi,

I am working with a new feed of data every week (in real time). Therefore, as real time passes my time series dataset increase in size and variable names change due to new real dates added (currently AE, but next (real) week it will become AD etc...)... I would like to identify variables by their order in the dataset. I would to be able to rename by two different methods (large project, I need to do it several times and need the 2 methods)
1) "the second variable in the dataset as currently ordered" and also
2) "the variable next (on the right) of a particular variable", in the example below "DATATYPE"

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 DATATYPE double(AE AF AG AH AI AJ)
"SP500_w" 6247.66 6375.54 6529.42 6389.67 6209.38 6075.76
"VIX_w"     33.84   33.47   27.57   25.66   27.62   27.99
end
This is how I currently rename the variables. I would like to replace "AE" by "the variable next to DATATYPE" or "the second variable in the dataset"
Code:
* Rename variables as t1, t2, t3 etc.
qui ds
    loc lastvar: word `c(k)' of `r(varlist)'
local j 0
foreach var of varlist AE-`lastvar' {
    local j `=`j'+1'
    rename `var' t`j'
}
Any idea how to solve this problem? Thanks.