Greetings everybody,

I have one big dataset with variables starting from v4 to v66, and I want to divide this big dataset into 21 separate datasets with 3 variables in each set. (dataset 1 includes variable v4, v5 and v6 dataset 2 includes variable v7, v8 and v9 ....and the like) I made this macro

local i 4
while `i' <= 66 {
insheet using "C:\Users\Lenovo\FileName.csv", comma clear
keep v`i' v`i+1' v`i+2'
save `i'.dta, replace
local i = `i' + 3
}

The "keep" command does not recognise v`i+1' and v`i+2'; it only keeps v`i'. Any ideas on how to tell Stata to keep the three variables for each dataset?

Thanks in advance.
L.