Hey Stata users!

I am trying to loop over a list of integer variables to replace missing values. I am using the following code


Code:
qui: ds S* PA* PB* PC* BST* H1* H2* H3* H4* H5*, not(type string)
local Int_vars `r(varlist)'

foreach v of local Int_vars {
        egen max_var = max(`v') - 4
        replace `v' = . if max_var>`v'
        drop max_var
}
When I use the code above, "varlist not allowed" as an error.

What part of my code am I getting wrong?

Thanks!