Bookmark and Share

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

[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
    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)

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]

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index