Hello, I am new to Mata and how do you calculate a running sum matrix?
-
Login or Register
- Log in with
: x = (1,2,3\4,5,6\7,8,9) : x 1 2 3 +-------------+ 1 | 1 2 3 | 2 | 4 5 6 | 3 | 7 8 9 | +-------------+ : wanted = J(rows(x), 0, .) : for(j = 1; j <= cols(x); j++) { > wanted = wanted , runningsum(x[, j]) > } : wanted 1 2 3 +----------------+ 1 | 1 2 3 | 2 | 5 7 9 | 3 | 12 15 18 | +----------------+
: x = (1,2,3\4,5,6\7,8,9) : x 1 2 3 +-------------+ 1 | 1 2 3 | 2 | 4 5 6 | 3 | 7 8 9 | +-------------+ : y = (1,0,0\1,1,0\1,1,1) : y*x 1 2 3 +----------------+ 1 | 1 2 3 | 2 | 5 7 9 | 3 | 12 15 18 | +----------------+
Comment