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]

[no subject]


From   Matthew J Baker <[email protected]>
To   [email protected]
Date   Fri, 4 Feb 2011 09:53:21 -0500 (EST)

Dear listers:

I have noticed that there can be a (small) discrepancy between 
the results produced by Stata's predict command after running 
a regression and what I think should generate identical 
results in Mata. As an illustration, when running the 
following code:

  sysuse auto, clear
  reg price weight length
  predict xb
  gen err=price-xb

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
  getmata err_mata
  sum err err_mata

I find that the results of the sum command are as follows 
(apologies for bad spacing)
spacing): 

    Variable |       Obs        Mean    Std. Dev.       Min        
Max
-------------+------------------------------------------------
--------
         err |        74   -.0000198    2382.413  -4432.274    
5771.01
    err_mata |        74    6.20e-06    2382.413  -4432.274    
5771.01

One can see that the numbers are all close but a little 
different - notably, the mean. What is the reason for this? 

Dr. Matthew J. Baker
Department of Economics
Hunter College and the Graduate Center, CUNY
*
*   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