Reputation: 9
Is there a way to quickly append the same suffix to a list of variables from monthly reports in Stata for example:
Variable list: report, total_enrollment
Append _jan22 so new variable list: report_jan22, total_enrollment_jan22
Variable list: report, total_enrollment
Append _feb22 so new variable list: report_feb22, total_enrollment_feb22
Have looked at the Rename * command -- advice on using this command?
Upvotes: 0
Views: 998
Reputation: 3255
Do you have multiple datasets or how can the variables have the same name in the first place?
One way to solve this would be to use a loop. Provide more detail if this does not work.
clear
set obs 10
gen report = 1
gen total_enrollment = 1
local vars report total_enrollment
foreach var of local vars {
rename `var' `var'_jan22
}
Upvotes: 1