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]
st: discrepancy predicted errors and mata computation [was: ""]
From
Maarten buis <[email protected]>
To
[email protected]
Subject
st: discrepancy predicted errors and mata computation [was: ""]
Date
Fri, 4 Feb 2011 15:11:26 +0000 (GMT)
--- On Fri, 4/2/11, Matthew J Baker wrote:
> 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.
That is because you predicted your outcomes as -float-s and
not -double-s. The difference becomes much smaller when
you do that, see the adjusted example below.
*---------- begin example --------------
sysuse auto, clear
reg price weight length
predict double xb
gen double 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, double
sum err err_mata
*----------- end example ---------------
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/