A Stata loop to add data source to variable labels

The Stata blog provides a loop to rename variables.

I use this loop to add the data source to variable names when I merge datasets together. Here is the loop for doing that:

foreach var of varlist * {
    local lab `: var label `var''
    label var `var' "(<data source name>) `lab'"

Replace <data source name> with the data source.