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: ereturn post after mata
From
Christoph Engel <[email protected]>
To
[email protected]
Subject
st: ereturn post after mata
Date
Tue, 06 Mar 2012 19:03:16 +0100
Dear readers of Stata list,
Cameron Trivedi: Microeconometrics Using Stata 2009, p. 116 report the
code for running OLS in mata, and posting the results in stata.
If I simplify the code and estimate a model with only one regressor and
no constant, it works just fine. But if I add the constant, I still get
coefficients and a variance/covariance matrix that are the same as the
ones generated by reg. But I can no longer display the results
conveniently. The following step does not work
ereturn post b V
I get the error code: r(504): matrix has missing values
The link to r(504) says that this should no longer be an issue.
Actually, I can use matrix list e(V) and get the same VCE as with reg.
Am I making a mistake, or is this a bug that Stata Corp should fix?
Here is my code which, I think, is exactly what Cameron Trivedi propose:
local y dv
local xlist iv cons
mata
st_view(y= ., ., "`y'")
st_view(X= ., ., tokens("`xlist'"))
XXinv = cholinv(cross(X,X))
b = XXinv*cross(X,y)
e = y - X*b
n = rows(X)
k = cols(X)
s2 = (e'e)/(n-k)
vdef = s2*XXinv
st_matrix("b", b')
st_matrix("V", vdef)
end
matrix colnames b = `xlist'
matrix colnames V = `xlist'
matrix rownames V = `xlist'
ereturn post b V
ereturn display
Thank you for any help
Christoph Engel
--
_________________________________________________________________
Prof. Dr. Christoph Engel
Max-Planck-Institut zur
Erforschung von Gemeinschaftsgütern
Max Planck Institute for Research on Collective Goods
Kurt-Schumacher-Strasse 10
D 53113 Bonn
Tel. +49/228/91416-10
Fax +49/228/91416-11
e-mail:[email protected]
http://www.coll.mpg.de
http://www.coll.mpg.de/engel.html
http://ideas.repec.org/e/pen22.html
http://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=251559
_________________________________________________________________
*
* 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/