Occasionally we want to use variable labels in loops or we want to apply them to other labels. a very simple local syntax function for that is local localname: variable label varname.
As an example, suppose that I have three variables (x, y, z) with their respective labels. I want to create three other variables with their mean and I want to label those variables using the labels from x, y and z. I can type:
global varlist1 x y x
foreach var in $varlist1 {
local label`var': variable label `var'
egen mean_`var' = mean(`var')
label variable mean`var' "Mean of `label`var' ' "
}
The same idea is also useful for graphs and other commands
Leave a Reply
You must be logged in to post a comment.