Technically, Stata 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.
mat v = (3\2\2) mat list v, nonames v[3,1] 3 2 2
mat vp = v' mat list vp, nonames vp[1,3] 3 2 2
mat w = (4\1\2) mat s = v + w mat list s, nonames s[3,1] 7 3 4
mat d = v - w mat list d, nonames d[3,1] -1 1 0
mat s = 3*v mat lis s, nonames s[3,1] 9 6 6 mat t = v*3 mat lis t, nonames t[3,1] 9 6 6
mat d = v'*w mat list d, nonames symmetric d[1,1] 18 mat d = w'*v mat list d, nonames symmetric d[1,1] 18 mat d = v'*v mat list d, nonames symmetric d[1,1] 17 mat d = w'*w mat list d, nonames symmetric d[1,1] 21
mat a = (4\3) mat list a, nonames a[2,1] 4 3 mat dp = a'*a display sqrt(el(dp,1,1)) 5 mat list v, nonames v[3,1] 3 2 2 mat dp = v'*v display sqrt(el(dp,1,1)) 4.1231056 mat list w, nonames w[3,1] 4 1 2 mat dp = w'*w display sqrt(el(dp,1,1)) 4.5825757
mat l = (1/2 \ 1/2 \ 1/2 \ 1/2) mat list l, nonames l[4,1] .5 .5 .5 .5 mat dp = l'*l display sqrt(el(dp,1,1)) 1
mat u = (1\1\1) mat list u, nonames u[3,1] 1 1 1 mat dp = u'*u mat list dp, nonames symmetric dp[1,1] 3 mat list v, nonames v[3,1] 3 2 2 mat dp = u'*v mat list dp, nonames symmetric dp[1,1] 7 mat list w, nonames w[3,1] 4 1 2 mat dp = u'*w mat list dp, nonames symmetric dp[1,1] 7
Multivariate Course Page
Phil Ender, 12feb05