Statalist


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

Re: st: Re: how to quietly svmat?


From   "Sergiy Radyakin" <serjradyakin@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: how to quietly svmat?
Date   Tue, 11 Nov 2008 17:17:42 -0500

Thank you Kit and Nick.

I have just one comment: the program will not work if the number of
rows in the matrix to be saved is larger than the current number of
obs:
.....
. svmat2 corr
               st_view():  3300  argument out of range
             mm_svmat2():     -  function returned error
                 <istmt>:     -  function returned error

 and fixing it resembles the code that I started with, so it's not
simplier after all.

Thank you, Sergiy


On Tue, Nov 11, 2008 at 4:16 PM, Christopher Baum <baum@bc.edu> wrote:
> Sorry; I had a nagging thought that this name may have been used, but did
> not check it out. Nick is quite right that more care should be taken to
> avoid stomping on existing names. (I was quite annoyed when the name of my
> -xttest1- routine, which had been circulating via SSC for a while, was
> usurped by a Stata Journal article!) For all 'svmat2' below read 'svmat22'.
>
> 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
>
> On Nov 11, 2008, at 4:11 PM, Nick Cox wrote:
>
>> I agree strongly with Kit's approach here. It's been several years since
>> I reached for -svmat-.
>>
>> However, Kit just plucked a program name out of the air, and
>> understandably forgot that the name -svmat2- was also used a while back
>> for a program in this territory which is not yet completely superseded.
>>
>> . search svmat2, historical
>>
>> gives the details. StataCorp's implication in its .key file coding that
>> -svmat2- is of historical interest only is not quite correct. Questions
>> to which "use -svmat2-" is the answer still arise about once per year on
>> Statalist.
>>
>> So, I suggest the use of some other name.
>>
>> Nick
>> n.j.cox@durham.ac.uk
>>
>> Christopher Baum
>>
>> 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
>
> *
> *   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/
>
*
*   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