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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: AW: Taking mata views of ereturn stats? |

Date |
Fri, 18 Dec 2009 19:14:38 +0100 |

<> Let`s make being "pedantic" a little more worthwhile: How can Skipper get rid of the zeroes in his varcov representing the base outcome in -mlogit-? HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: Freitag, 18. Dezember 2009 18:29 To: statalist@hsphsun2.harvard.edu Subject: st: RE: AW: Taking mata views of ereturn stats? This isn't quite true, in the pedantic sense that you don't have to use the colon (elementwise) operator. webuse sysdsn1, clear mlogit insure age male nonwhite i.site mata: sqrt(diagonal(st_matrix("e(V)"))) will do the same thing. Using Mata's -sqrt()- function may seem no different from using a power function and specifying 0.5 as the power. However, in most languages I know a bit about, using a square root function is at least a smidgen more direct and more efficient when that's what you want. Typically, there is no homunculus inside the powering code and saying "Oh, you really want a square root" and redirecting traffic accordingly. Nick n.j.cox@durham.ac.uk Martin Weiss Note you have to use the colon for elementwise taking of the square root: ************* webuse sysdsn1, clear mlogit insure age male nonwhite i.site mata V=st_matrix("e(V)") se = diagonal(V):^0.5 se end ************* Skipper Seabold I am trying to get used to Stata's mata environment. I am somewhat familiar with Stata but as far as the matrix operations am more familiar with environments like R, Matlab, or Python, and am having some trouble using Stata in the same way, though I understand that mata is C-like. For instance, say I want to do something like have a vector of the standard errors that I can access element-wise. Is there a quick way to go between stata and mata to do this. Given the following example, webuse sysdsn1 mlogit insure age male nonwhite i.site Is there a quick way to get e(V) into a matrix so that I can do element-wise operations like taking the square root of the diagonal? I was thinking that I could just assign e(V) to a matrix, then take a view on this in mata, but this doesn't seem to be the way that Stata works. Alternatively, I think I could save e(V) to a datset and load it so that V is the dataset and use st_data or st_view, or I could just program the whole estimator in mata, but this all seems like overkill for something that's seems so natural in other environments. * * 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/

**References**:**st: Taking mata views of ereturn stats?***From:*Skipper Seabold <jsseabold@gmail.com>

**st: AW: Taking mata views of ereturn stats?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: AW: Taking mata views of ereturn stats?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: Taking mata views of ereturn stats?** - Next by Date:
**Re: st: RE: RE: AW: Taking mata views of ereturn stats?** - Previous by thread:
**st: RE: AW: Taking mata views of ereturn stats?** - Next by thread:
**Re: st: RE: RE: AW: Taking mata views of ereturn stats?** - Index(es):

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