I have multiple sheets of excel that I import one by one into Stata. Each of the sheets has about 150 variables. The suffix of the variables is always either *_dum or *_yr. In Stata, I want to keep the label of *_dum, and the value of *_yr.

Regardless of the number of variables and the specific prefixes in each sheet, I want to create a code that will replace the variable label of those that end with "_yr" by the label in "_dum", if they have the same prefix. Prefixes will vary depending on the Excel input.

For instance 7_2_2_1_dum label needs to replace 7_2_2_1_yr label. Having both the label and the value that I want in 7_2_2_1_yr, I can now drop 7_2_2_1_dum.

Thank you.