program define norm version 4.0 /* This program takes a list of vectors, given by the first */ /* variable (the name of a string) and a scalar into which */ /* it places the largest norm of the difference between any */ /* two of the vectors. The trace option causes the program */ /* to list the vectors it is looking at and the likelihood */ /* value at each of these vectors; the lf option must */ /* contain the likelihood function to be used if the trace */ /* option is specified. */ local f "`1'" /* Name of scalar to contain log likelihood */ macro shift 1 local options "SIMPLEX(string) TRACE LF(string)" parse "`*'" local vecsize : word count `simplex' tempname j_min_i normvec lf_val local i = 1 local maxnorm = 0 scalar `lf_val' = 0 while `i' <= `vecsize' -1 { local ith_vec : word `i' of `simplex' if "`trace'" != "" { display "Vector number `i':" matrix list `ith_vec' `lf' `ith_vec' `lf_val' display "Likelihood: " `lf_val' _n _n } local j = `i' + 1 while `j' <= `vecsize' { local jth_vec : word `j' of `simplex' matrix `j_min_i' = `ith_vec' - `jth_vec' matrix `normvec' = `j_min_i' * `j_min_i'' local ijth = el(`normvec',1,1) local ijth = sqrt(`ijth') if `ijth' > `maxnorm' { local maxnorm = `ijth' } local j = `j' + 1 } local i = `i' + 1 } if "`trace'" != "" { display "Vector number `i':" local ith_vec : word `i' of `simplex' matrix list `ith_vec' `lf' `ith_vec' `lf_val' display "Likelihood: " `lf_val' _n _n display "Maximum norm is `maxnorm'" } scalar `f' = `maxnorm' end