Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: re: how to quietly svmat?


From   Christopher Baum <[email protected]>
To   [email protected]
Subject   st: re: how to quietly svmat?
Date   Tue, 11 Nov 2008 16:02:27 -0500

<>
Just avoid it entirely and do it in Mata:

mata:mata clear
mata:
void function mm_svmat2(string scalar mat, string scalar vlist)
{
	m = st_matrix(mat)
	vv = tokens(vlist)
	st_view(X=., 1::rows(m), vv)
	X[. , .] = m
}
end

program drop _all
prog svmat2
syntax anything [,stub(string)]
local vn = cond("`stub'" == "", "var", "`stub'")
scalar nc = colsof(`anything')
forv i=1/`=nc' {
	local vname "`vn'`i'"
	qui gen double `vname' = .
	local vl "`vl' `vname'"
}
mata: mm_svmat2("`anything'","`vl'")
end

webuse auto, clear
qui corr price mpg headroom trunk weight length
mat corr=r(C)

svmat2 corr
svmat2 corr, stub(sergiy)
su


Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index