Dear Stata users,
I have three variables, I want to create a local that adds sequential number before each variable and interaction of the last two ones. Below is what I want to get:
1 "mpg" 2 "rep78" 3 "foreign" 4 "rep78#foreign"
I have three variables, I want to create a local that adds sequential number before each variable and interaction of the last two ones. Below is what I want to get:
1 "mpg" 2 "rep78" 3 "foreign" 4 "rep78#foreign"
Code:
forvalues n= 1/4 { //In real applying case, the max number of `n' should be determined by count of variables plus 1.
tokenize mpg rep78 foreign
local first `1'
local relabel `relabel' `n' "`first'"
}
display `"`relabel'"' //the result is certainly not what I desire: 1 "mpg" 2 "rep78" 3 "foreign" 4 "rep78#foreign"
1 "mpg" 2 "mpg" 3 "mpg" 4 "mpg"

Comment