# Re: st: -estimates table- display question

 From Maarten buis <[email protected]> To [email protected] Subject Re: st: -estimates table- display question Date Sat, 20 Jan 2007 18:06:48 +0000 (GMT)

```--- "Michael S. Hanson" <[email protected]> wrote:
> I have written a
> short .do file that simulates a series of random (x,y) draws from a
> simple linear relationship to illustrate the difference between the
> population regression relationship and the estimated sample
> regression line, as well as the role of sampling variation, for my
> econometrics course this semester. <snip>  Notice that the p-values
> that are reported in the -est table- command are not particularly
> interesting for this application;  rather, I'd like to list the p-
> values that correspond to the following tests, given that the true
> population parameters are known in this simulation:
>
> 	test _b[_cons] = a
> 	test _b[x] = b
> 	test (_b[_cons] = a) (_b[x] = b)
>
> for pedagogical reasons, I'd prefer the p-values to be
> grouped with the coefficient estimates and SEs, rather than lumped
> with the other summary statistics for the regression as a whole.  Is>

> this possible?

Note that the t-value of the test you propose for x is:
(_b[x]-b)/_se[s]. The p-value associated with that is
2*ttail(e(df_r),abs((_b[x]-b)/_se[s])). You can store this together
with the other coefficients in a matrix and use -matlist- to show the
results in a table that looks pretty close to the results from -est
table-. See example 1 below. For cases like these I actually prefer
graphs. This way you can meaningfully show the results from a lot more
regressions. See example 2 below.

Hope this helps,
Maarten

*----------- begin example 1 ---------------
set more off
clear
local m = 10
local n = 100
matrix sd = 1
scalar r = 1
scalar a = 1
scalar b = 1

forvalues i = 1/`m' {
drawnorm u`i', n(`n') sds(sd)
}

gen x = uniform()*r
sort x

local ncols = `m' + 1
matrix result = J(8, `ncols',.)

gen ytrue = a + b*x
quietly regress ytrue x
est store true
matrix res = _b[x] \      ///
_se[x] \     ///
1 \          ///
_b[_cons] \  ///
_se[_cons] \ ///
1 \          ///
e(r2) \      ///
e(rmse)
matrix result[1,1] = res
matrix list result

set traced 1
*set trace on
forval i = 1/`m' {
gen y`i' = ytrue + u`i'
quietly regress y`i' x
quietly predict y`i'hat
est store reg`i'
matrix res = _b[x] \                                        ///
_se[x] \                                         ///
2*ttail(e(df_r),abs((_b[x]-b)/_se[x])) \         ///
_b[_cons] \                                      ///
_se[_cons] \                                     ///
2*ttail(e(df_r),abs((_b[_cons]-a)/_se[_cons])) \ ///
e(r2) \                                          ///
e(rmse)
local j = `i' + 1
matrix result[1,`j'] = res
}

est table *, b(%4.2f) se p stats(r2 rmse)

matrix rownames result = x:b x:se x:p /*
*/ _cons:b _cons:se _cons:p /*
*/ fit:r2 fit:rmse
local colnames "true"
forval i = 1/`m' {
local colnames "`colnames' reg`i'"
}

matrix colnames result = `colnames'

matlist result, format(%9.3f)
*------------ end example 1 ----------------

*----------- begin example 2 ---------------
set more off
clear
local m = 50
local n = 100
matrix sd = 1
scalar r = 1
scalar a = 1
scalar b = 1

forvalues i = 1/`m' {
drawnorm u`i', n(`n') sds(sd)
}

gen x = uniform()*r
sort x

local ncols = `m' + 1
matrix result = J(8, `ncols',.)

gen ytrue = a + b*x
quietly regress ytrue x

tempname memhold
tempfile results
postfile `memhold' bx lbx ubx b_cons lb_cons ub_cons r2 rmse /*
*/ using `results'
forval i = 1/`m' {
gen y`i' = ytrue + u`i'
quietly regress y`i' x
quietly predict y`i'hat
local lbx = _b[x] - invttail(e(df_r),0.025)*_se[x]
local ubx = _b[x] + invttail(e(df_r),0.025)*_se[x]
local lb_cons = _b[_cons] - invttail(e(df_r),0.025)*_se[_cons]
local ub_cons = _b[_cons] + invttail(e(df_r),0.025)*_se[_cons]
post `memhold' (_b[x]) (`lbx') (`ubx') /*
*/ (_b[_cons]) (`lb_cons') (`ub_cons') /*
*/ (e(r2)) (e(rmse))
}
postclose `memhold'

preserve
use `results', clear
gen sample = _n
local b = scalar(b)
local a = scalar(a)
twoway rcap lbx ubx sample, horizontal || /*
*/ scatter sample bx, xline(`b') name(x) /*
*/ legend(label(1 "95% confidence" "interval") /*
*/  label(2 "b"))
twoway rcap lbx ubx sample, horizontal || /*
*/ scatter sample bx, xline(`a') name(cons) /*
*/ legend(label(1 "95% confidence" "interval") /*
*/  label(2 "_cons"))
hist r2, name(r2)
hist rmse, name(rmse)
restore
*------------ end example 2 ----------------

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

___________________________________________________________
New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk
*
*   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/
```