*! version 1.0.0 10jul1997 program define datmat /* newvarlist = (oldvarlist)*matrix */ version 5.0 parse "`*'", parse(" =()*,") /* Get new varlist. */ while "`1'"!="" & "`1'"!="=" { local varnew "`varnew' `1'" macro shift } if "`1'"!="=" { error 198 } macro shift if "`1'"!="(" { error 198 } macro shift /* Get old varlist. */ while "`1'"!="" & "`1'"!=")" { local varold "`varold' `1'" macro shift } if "`1'"!=")" { error 198 } macro shift if "`1'"!="*" { error 198 } macro shift /* Get matrix. */ local M "`1'" macro shift cap di matrix(`M'[1,1]) if _rc { di in red "matrix `M' not found" error 111 } /* Parse new varlist. */ nobreak { local varlist "req new" parse "`varnew'" local var1 : word 1 of `varlist' local type : type `var1' drop `varlist' } local varnew "`varlist'" /* Parse old varlist, if, in, and options. */ local varlist "req ex" local if "opt" local in "opt" parse "`varold' `*'" /* Check conformability. */ local dim1 : word count `varlist' local dim2 : word count `varnew' local dim = rowsof(matrix(`M')) if `dim'!=`dim1' { error 503 } local dim = colsof(matrix(`M')) if `dim'!=`dim2' { error 503 } /* Do multiplications. */ tempname A parse "`varnew'", parse(" ") local i 1 while `i' <= `dim2' { matrix `A' = `M'[.,`i'] matrix `A' = `A'' matrix colnames `A' = `varlist' qui matrix score `type' ``i'' = `A' `if' `in' local i = `i' + 1 } end exit