I just want to compute descriptive statistics of the categorical time-invariant variables in the attached longitudinal data file.
For the sake of efficiency, I used the following for-loop code to compute them.
However, something is wrong and I couldn't find what places are incorrect.

Thanks for your suggestions and help!

use data.dta,clear
local a male esl_pgm bil_pgm everspec hispanic
foreach var of a {
preserve
bys id: keep if _n==1
sum `var'
restore
}