Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: change values of e(b)


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: change values of e(b)
Date   Wed, 4 Dec 2002 12:13:08 -0000

Joseph Coveney
> 
> Hung-Jen Wang asked, "Is there any way to change elements 
> of the coefficient vector 
> e(b) obtained after an estimation?  . . . I want to work 
> with e(b) since I'll later use -
> predict- to do some experiments, and I assume that 
> -predict- recognizes e(b) only."
> 
> Yes.  You can force Stata into altering system matrixes 
> such as e(b) by writing a simple 
> wrapper eclass program that alters them, as in the 
> following illustrative do-file.  -predict- 
> will then use your altered e(b) matrix.
> 
> Joseph Coveney
> 
> ------------------------------------------------------------
> --------------------
> 
> drawnorm y x, n(20) mean(0 0) sd(1 1) /*
>   */ corr(1.0, 0.7 \ 0.7, 1.0) seed(20021204) clear
> regress y x
> matrix list e(b)
> predict real_hat, xb
> capture program drop alterations
> program define alterations, eclass
>     quietly regress y x
>     matrix A = e(b)
>     matrix A[1,1] = -A[1,1]
>     estimates repost b = A
> end
> alterations
> matrix list e(b)
> predict phony_hat, xb
> label variable phony_hat "phony"
> label variable real_hat "real"
> graph y real_hat phony_hat x, connect(.LL) symbol(Oii) /*
>   */ xlabel ylabel
> exit
> 
> ------------------------------------------------------------
> --------------------

This is, to me, a valuable correction to my 
earlier assertion that you can't do it. 

I'd still argue that it is bad style to 
do this, even if, as in this case, you know exactly 
what you are doing. 

I will assert that for -predict- to remain 
meaning "predict using the last model and 
the last data", and for eclass results 
to remain mutually consistent, it is 
better not to do this, or at least to make 
this a private habit and to flag any programs 
which do this with a caveat. 

Nick 
[email protected] 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index