Resp1 - Resp3 contain byte values of student_id.
Here is a snapshot of the data.
class_id | student_id | Resp1 | Resp2 | Resp3 |
1 | 1 | 9 | 7 | 5 |
1 | 2 | 14 | 4 | 22 |
1 | 3 | 1 | . | 22 |
1 | 28 | 30 | 1 | 1 |
1 | 29 | 2 | 22 | 4 |
1 | 30 | 9 | . | 18 |
2 | 1 | 3 | 15 | 13 |
2 | 2 | 17 | 25 | 1 |
2 | 3 | 3 | 17 | 9 |
My goal in using tabcount is to eventually create a variable that contains frequency of student_id for each observation of a student_id in a class_id.
Essentially, this command below, but across all Resp variables, with student_ids with zero occurrences included, missing excluded from display.
bysort student_id (class_id): tab PN1, matcell(matrix`Class')
svmat matrix`Class'
My thought is tabcount should be able to handle this. But when I run the following, I receive a type mismatch r(109) error. None of the variables are string. Could it be I'm misusing a macro? (I also don't quite understand how what arguments c() or v() are supposed to take.)
vl create Resp_list = (Resp1 Resp2 Resp3)
foreach var in $Resp_list{
di "Var is: `var'"
bysort class_id (student_id): tabcount `var', c(`var') zero
}
Any help is appreciated!
0 Response to Type Mismatch Error with tabcount
Post a Comment