1606281735 Lists of variables: looping over two lists

TIP 6 : Loop over 2 lists

It is - indirectly - possible! And sometimes very useful: for example if you want to rename a (long) list of variables.

One solution is to loop over one index i (identical) corresponding to the rank of both the variable name and the variable label in the two lists. Then you get the i-th word for each list and rename accordingly.

global list_var "var1 var2"

global list_rename "sexe age"

local `n' : word count ${list_rename}

forvalues i = 1/`n' {

local a : word `i' of ${list_var}

local b : word `i' of ${list_rename}

rename `a' `b'

}

results matching ""

    No results matching ""