I have a dataset with 28 string variables named"ox*tc", and the * represent to number 02, 03, ..., 31. They are all string variables with values ranged from letter "A" to "T". Now I'd like to creat a new variable, counting the total number of "T" or "A" in these variables. I tried foreach loop but it doesn't work, with some issues about the abbreviation.
Code:
foreach v of varlist ox*tc { count if ox*tc=="A" | ox*tc=="T" }
Code:
forvalues i in 2/31{ foreach v of varlist ox`i'tc { count if ox`i'tc=="A" | ox`i'tc=="T" } }
0 Response to Using -foreach- to count for string variables
Post a Comment