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

st: re: how to quietly svmat?

From   Kit Baum <>
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
void function mm_svmat22(string scalar mat, string scalar vlist)
	st_view(X=., 1::rows(st_matrix(mat)), tokens(vlist))
	X[. , .] = st_matrix(mat)
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'")

// 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)

Kit Baum, Boston College Economics and DIW Berlin
An Introduction to Modern Econometrics Using Stata:

*   For searches and help try:

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