Hi statalist colleagues,

I was struggling with a quite simple thing I guess.

Code:
foreach v of varlist YSVR9909ASREPGDP - YSVR2105ASREPGDP {
    replace temp_`v' = `v' - `v-1'
    tab temp_`v'
}
What I am trying to create is a variable where I take the difference between the two variables in the variable list.


So if there is var1 var2 var3

I am trying to create

temp_var2 = var2-var1
temp_var3 = var3-var2

I couldn't figure this out, as pointing to a previous column was not doable with [_n-1] or L. which are only used for rows(i.e. observations).

It would be great if someone could share their knowledge on this.

Thanks much,

Ed