Mata is the new interactive matrix command language that comes with Stata beginning with Stata 9. To start Mata, type meta in the Stata command window. The end a Mata session, type end and press return.
Technically, Mata does not have any dedicated vector commands, it merely treats vectors as matrices with one column or one row. Thus, there are no commands for dot product or vector norm. We can still get the results we need using matrix commands in Mata.
mata : v = (3\2\2) : v 1 +-----+ 1 | 3 | 2 | 2 | 3 | 2 | +-----+
: vp = v' : vp 1 2 3 +-------------+ 1 | 3 2 2 | +-------------+
: w = (4\1\2) : s = v + w : s 1 +-----+ 1 | 7 | 2 | 3 | 3 | 4 | +-----+
: d = v - w : d 1 +------+ 1 | -1 | 2 | 1 | 3 | 0 | +------+
: s = 3*v : s 1 +-----+ 1 | 9 | 2 | 6 | 3 | 6 | +-----+ : t = v*3 : t 1 +-----+ 1 | 9 | 2 | 6 | 3 | 6 | +-----+
: d = v'*w : d 18 : d = w'*v : d 18 : d = v'*v : d 17 : d = w'*w : d 21
: a = (4\3) : a 1 +-----+ 1 | 4 | 2 | 3 | +-----+ : l = sqrt(a'*a) : l 5 : v 1 +-----+ 1 | 3 | 2 | 2 | 3 | 2 | +-----+ : l = sqrt(v'*v) : l 4.123105626 : w 1 +-----+ 1 | 4 | 2 | 1 | 3 | 2 | +-----+ : l = sqrt(w'*w) : l 4.582575695
: ul = (1/2 \ 1/2 \ 1/2 \ 1/2) : ul 1 +------+ 1 | .5 | 2 | .5 | 3 | .5 | 4 | .5 | +------+ : l = sqrt(ul'*ul) : l 1
: u = (1\1\1) : u 1 +-----+ 1 | 1 | 2 | 1 | 3 | 1 | +-----+ : l = u'*u : l 3 : v 1 +-----+ 1 | 3 | 2 | 2 | 3 | 2 | +-----+ : dp = u'*v : dp 7 : w 1 +-----+ 1 | 4 | 2 | 1 | 3 | 2 | +-----+ : dp = u'*w : dp 7
Multivariate Course Page
Phil Ender, 2may05