Hello!
I am working with a longitudinal data with repeat measures. The person programming the survey placed suffixes do denote survey at the end of most variables, but for some, the "suffix" is actually in the middle of the variable. For example, what should be fu_a_time___1 is fu_a_time_v2___1. This is making reshaping the data quite difficult and so I am trying to figure out how to efficiently drop the v2 from with the name for visits 2-9. I have tried this code:
While it does not produce an error, the data in memory don't actually change.
Any ideas or suggestions would be welcomed!
I am working with a longitudinal data with repeat measures. The person programming the survey placed suffixes do denote survey at the end of most variables, but for some, the "suffix" is actually in the middle of the variable. For example, what should be fu_a_time___1 is fu_a_time_v2___1. This is making reshaping the data quite difficult and so I am trying to figure out how to efficiently drop the v2 from with the name for visits 2-9. I have tried this code:
Code:
foreach var of varlist fu_a_time_v2___1 [rest of vars] { local newname : subinstr local var "__v2" "", all if "`newname'" != "`var'" { rename `var' `newname' } }
Any ideas or suggestions would be welcomed!
Comment