Hi,

I'm trying to merge data from a yearly questionnaire to form a panel.

The date follows the following format:
  • cp08a_m
  • cp09b_m
  • cp10c_m
That is, cp, two numbers representing the year, a letter and then _m. I want to rename them all as "date".

Meanwhile, the questions' name follow the follow pattern:
  • cp08a001
  • cp08a002
  • cp09b001
  • cp09b002
That is, cp, two numbers representing the year, a letter and then three numbers representing the question number.

So far, I've tried this:

Code:
forval n = 1/10 {
    use "$path\Originales\Personality`n'.dta", clear
    tsunab year : c*_m
    rename `year' date
    replace date = 2007+`n'
    tsunab q : c*(###)
    rename `q' P(###)
    save "$path\Modifiees\Personality`n'_m.dta", replace
    clear
}
It successfully renames everything into date but the second tsunab, " tsunab q : c*(###)", returns "# invalid name". I've tried basically every iteration with wildcards I can think of, to no avail. I always get an invalid name or an unfound variable (e.g., c).

Thank!