Statalist


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

st: re: how to quietly svmat?


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: re: how to quietly svmat?
Date   Tue, 11 Nov 2008 19:38:28 -0500

< >
Easy enough to fix the fact that the current number of obs is fewer than the number of rows in the matrix (and shorten the code a bit):

program drop _all
mata:mata clear
mata:
void function mm_svmat22(string scalar mat, string scalar vlist)
{
	st_view(X=., 1::rows(st_matrix(mat)), tokens(vlist))
	X[. , .] = st_matrix(mat)
}
end
prog svmat22
syntax anything [,stub(string)]
local vn = cond("`stub'" == "", "var", "`stub'")
qui desc
set obs `=max(r(N), colsof(`anything'))'
forv i=1/`=colsof(`anything')' {
	local vname "`vn'`i'"
	qui gen double `vname' = .
	local vl "`vl' `vname'"
}
mata: mm_svmat22("`anything'","`vl'")
end

// try it out
webuse auto, clear
keep in 1/3
qui corr price mpg headroom trunk weight length
mat corr=r(C)

svmat22 corr
svmat22 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index