use http://www.stata-press.com/data/dsemusr/bmiworking.dta, clear sem (bmi97-bmi09 <- Int@1), method(mlmv) from(starts) matrix starts = e(b) matrix A = starts local colnm : colfullnames A display "`colnm'" local colnm : subinstr local colnm "_cons" "intercept", all local colnm : subinstr local colnm ":" "_c_", all local colnm : subinstr local colnm "(" "_l_", all local colnm : subinstr local colnm ")" "_r_", all local colnm : subinstr local colnm "." "_p_", all display "`colnm'" matrix colnames A = `colnm' matrix list A clear svmat A, names(col) save coeffs.dta, replace use coeffs.dta, clear mkmat _all, matrix(B) local colnm : colfullnames B local colnm : subinstr local colnm "_p_" ".", all local colnm : subinstr local colnm "_r_" ")", all local colnm : subinstr local colnm "_l_" "(", all local colnm : subinstr local colnm "_c_" ":", all local colnm : subinstr local colnm "intercept" "_cons", all display "`colnm'" matrix colnames B = `colnm' matrix list B use http://www.stata-press.com/data/dsemusr/bmiworking.dta, clear sem (bmi97-bmi09 <- Int@1 ), method(mlmv) noconstant means(Int) from(B) // a better idea might be to transpose and store column names in a var // The benefit is that we don't have to worry if matrix column names // conform to Stata's rules for data set variable names matrix A = starts' clear svmat A gen str32 colnm = "" gen str32 coleq = "" local colnm : colnames starts local coleq : coleq starts local cols : word count `colnm' *display "`colnm'" *display "`cols'" forvalues i=1/`cols' { *display "`i'" "`: word `i' of `coleq''" "`: word `i' of `colnm''" replace colnm = "`: word `i' of `colnm''" in `i' replace coleq = "`: word `i' of `coleq''" in `i' } save coeffslong.dta, replace use coeffslong.dta, clear mkmat A, matrix(B) rownames(colnm) roweq(coleq) matrix C = B' local colnm : rowfullnames B matrix colnames C = `colnm' matrix list C