There is some unclarity in what you request.. I'm going to assume you mean: "From a given list of variables, randomly select three of them without replacement, and for each observation of a selected variable, assign its values to the same observation of a new variable." You might mean something different.
Code:
clear sysuse auto // Assemble a list of variables for illustration ds local setvars = "`r(varlist)'" // local size : word count `setvars' forval i = 1/3 { local nextvar = word("`setvars'", runiformint(1, `size')) di "newvar`i' will get the values of `nextvar'." gen newvar`i' = `nextvar' // Don't pick this var again local setvars = subinstr("`setvars'", "`nextvar'", "", 1) local size = `size' - 1 }
Comment