Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

re: Re: st: Re: Comparison of results from Stata


From   Christopher Baum <[email protected]>
To   <[email protected]>
Subject   re: Re: st: Re: Comparison of results from Stata
Date   Sun, 6 Feb 2011 20:39:11 -0500

<>
In any case: this begs the question: what is "reg" doing 
differently? While running your code makes the errors much 
closer, they still aren't identical - why is that?

Bill Gould will no doubt speak authoritatively on this point, but one reason why -regress- gets a different answer might be:

>>     mata
>>       st_view(X=.,.,"weight length")
>>       X=X,J(rows(X),1,1)
>>       st_view(Y=.,.,"price")
>>       beta=invsym(X'X)*X'Y
>>       err_mata=Y-X*beta
>>     end

If you want to solve the system of linear equations (X'X)b = X;'y, the least numerically stable way to do that is to use the inverse matrix. (That may or may not be a direct quote from one of Bill's SUG talks). Numerical analysts have devised far more stable and robust ways of solving that system of equations, particularly in the case of ill-conditioning of X'X, such as the LU-decomposition and the QR-decomposition. I suspect that Stata's architects, obsessive as they are about computing things the most accurate and stable way possible, are doing just that with -regress-. We (Baum, Schaffer, Stillman) have been bitten by this when developing -ivreg2-: the older version ended up using -regress- in its innards. The newer, Mata-ized version does not, and does not get quite as accurate an answer. But it does match -ivregress-, which uses Mata-based logic, versus the old -ivreg-, which used -regress-.

It may also be that to form X'X and X'y, you would be better off using Mata function quadcross() than doing the explicit matrix multiplications in "merely" double precision.

Kit

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index