I have a dataset with ~2500 variables named NEIS* and I want to:
- Delete all variables that have the same number repeated across all observations regardless of whether there are missing values in the column.

Below is the chunk of code I was using and the error message and a picture highlighting the variables I want to delete.



Code:
foreach myvar of varlist NEIS* {
  sort `myvar'
  summarize `myvar'
  scalar sd_ = r(sd)      *columns with the same number will have a std deviation of 0
  if (`myvar'[1] == `myvar'[_N]) drop `myvar'  *Delete all variables that have the same number
  if ( `sd_' == 0) drop `myvar' *this is where I think my code fails
  scalar drop _all  *drop scalar to prevent reuse by another loop
  }
Stata version 15.1 on Windows 10


Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
NEIS0001 | 6 27 0 27 27
==0 invalid name
r(198);

NEIS0001 NEIS2267 NEIS3000 NEIS3169 NEIS3170 NEIS3171 NEIS3172 NEIS3173
2 17 1 99992 2 99991 8 999920
2 2 99992 99991 8 999920
2 2 3 5 8 999920
2 56 1 99991 8
2 2 8 999920
2 2 456 99991 8 999920
Array