Hi, I got a 100 variables, each having a different name but not any sequence in the name. I wants to create another 100 variables by multiplying the 100 variables with a new variable called "ABC". I am successful in doing so easily with a simple loop (command 1) provided on one of the forums.
Command 1:
foreach var of varlist Ist variable name - 100th Variable name {
gen ABC_`var' = ABC*`var'
}
The command given above generates 100 variables each having their previous name starting with ABC_. However, the problem is that I also needs the "Variable Label" copied with new 100 variables from previous 100 hundred variables. I tried this with the given command 2.
Command 2:
foreach var of varlist Ist variable name - 100th Variable name {
labgen2 ABC_`var' "ABC_`labels'"= ABC*`var'
}
The command 2 provides Variable Label only "ABC_" However I needs the actual variable Label together with "ABC_" e.g. ABC_label1. I wish to get copy the variable label from the actual variable, combine it with ABC_ and copy it automatically with a new generated variable (for all 100 variables).
Help will be appreciated. Thanks
Command 1:
foreach var of varlist Ist variable name - 100th Variable name {
gen ABC_`var' = ABC*`var'
}
The command given above generates 100 variables each having their previous name starting with ABC_. However, the problem is that I also needs the "Variable Label" copied with new 100 variables from previous 100 hundred variables. I tried this with the given command 2.
Command 2:
foreach var of varlist Ist variable name - 100th Variable name {
labgen2 ABC_`var' "ABC_`labels'"= ABC*`var'
}
The command 2 provides Variable Label only "ABC_" However I needs the actual variable Label together with "ABC_" e.g. ABC_label1. I wish to get copy the variable label from the actual variable, combine it with ABC_ and copy it automatically with a new generated variable (for all 100 variables).
Help will be appreciated. Thanks
Comment