On Tue, 27 Mar 2012, clarodina clarodina wrote:
How to do a yes no calculation on matrix?
Matrix m has 2 columns class A and class B and 200 rows exam scores 0 - 100
Each row is 1 student
Want to sum the the number of students in class A with scores between 40
and 60
This is a calculation that's probably easier to do using a
spreadsheet, but you can do it in gretl:
matrix A = {10,55,60,30,80,43,100}'
matrix A39 = 39*ones(rows(A), cols(A))
matrix A61 = 61*ones(rows(A), cols(A))
matrix Atest = (A .> A39) .* (A .< A61)
print Atest
scalar n_40_60 = sumc(Atest)
or, if you prefer
matrix A = {10,55,60,30,80,43,100}'
n_40_60 = 0
loop i=1..rows(A) --quiet
n_40_60 += A[i] >= 40 && A[i] <= 60
endloop
print n_40_60
--
Allin Cottrell
Department of Economics
Wake Forest University, NC