Hello, I want to reshape a dataset with many stubs. I tried to put the stubs in a local following link below. When I run it Stata tells me the variable doesn't exist, even though a variable with this name exists and it works if I put in the stubs manually. I am sure it's a quite obvious error, but I can't figure out my mistake.

https://www.stata.com/statalist/arch.../msg00506.html

Here is a minimum working example:

Code:
clear
input ID SD_C1_01_2017 SD_C1_02_2017 SD_C1_01_2018 SD_C1_02_2018
1 50 85 30 40
2 30 0 0 40
3 10 20 0 0
end 


* Put all the needed future in a local macro
unab stublist: SD_C1*


* Cut out the year (e.g. _2007) at the end to obtain the actual stubs
foreach v of local stublist {
    local stubs `"`stubs' `= substr("`v'",1,length("`v'")-4)'"' 
} 


* Reshape automatically (does not work)
reshape long `stubs' , i(ID) j(Year)


* Reshape manually (works)
reshape long SD_C1_01_ SD_C1_02_ , i(ID) j(Year)