Adding F-tests using outreg2
*******If
you do not see the menu on the left click here to see it
NOTE:
If you copy-and-paste the code below to Stata re-type the all the quotes (both single and double)
Example:
clear
/*Using test data */
sysuse auto
/*Running a regression*/
regress mpg foreign weight length
/*Saving the p-value for
the model?s F-test in a local macro*/
local fmodel
= Ftail(`e(df_m)',`e(df_r)',`e(F)')
/*Running some individual F-tests*/
test foreign=length
/*Saving the p-value for
the custom F-test in a local macro*/
local test1=r(p)
/*Running additional F-test*/
test weight
/*Saving the p-value for
the custom F-test in a local macro*/
local test2=r(p)
/*Adding F-tests using addstat*/
outreg2 using test, addstat("F test model", e(F),"P-value of F
model", `fmodel',
"Foreign=Length",`test1', "Weight=0",`test2') word
replace
You will get
For more options for outreg2 type
help outreg2
See the following document for more options using outreg2
http://www.princeton.edu/~otorres/Outreg2.pdf
NOTE: outreg2 is a user-defined program; you may need to install
it by typing
ssc install
outreg2
Additional guides:
http://www.princeton.edu/~otorres/Regression101.pdf#page=33
http://www.princeton.edu/~otorres/Regression101.pdf#page=34
http://www.princeton.edu/~otorres/Regression101.pdf#page=35
Sources:
http://www.kellogg.northwestern.edu/rc/docs/outreg.pdf
http://www.stata.com/statalist/archive/2008-01/msg00382.html
Using Outreg2 with Ivreg
*******If
you do not see the menu on the left click here to see it
NOTE:
If you copy-and-paste the code below to Stata re-type the all the quotes (in
particular this one ` which is not same as ?)
*Source:
http://www.stata.com/statalist/archive/2009-09/msg00043.html
*! ivreg2out 0.9 roywada@hotmail.com
prog define ivreg2out, eclass
version 8.0
qui {
args one two
local name1=subinstr("`one'","_ivreg2_","",1)
local name2=subinstr("`two'","_ivreg2_","",1)
est restore `one'
mat b1=e(b)
mat V1=e(V)
matrix coleq b1 = `name1'
matrix coleq V1 = `name1'
local r2_first=e(r2)
est restore `two'
mat b2=e(b)
mat V2=e(V)
matrix coleq b2 = `name2'
matrix coleq V2 = `name2'
mat b=b1,b2
mat v1=vecdiag(V1)
mat v2=vecdiag(V2)
mat v=v1,v2
mat V=diag(v)
local r2_second=e(r2)
local N=e(N)
eret post b V
eret scalar N=`N'
eret scalar r2_1=`r2_first'
eret scalar r2_2=`r2_second'
eret loc eqnames= "`name1' `name2'"
eret loc depvar= "`name1' `name2'"
}
end
*** ivreg2 results stacked togehter
sysuse auto, clear
ivreg2 price headroom trunk (mpg=rep78 foreign), savefirst
first
est store _ivreg2_price
ivreg2out _ivreg2_mpg _ivreg2_price
outreg2 using myfile, replace long nor2 adds("r2
first", e(r2_1), "r2 second", e(r2_2)) word
*** ivreg2 results not-so stacked togehter
sysuse auto, clear
ivreg2 price headroom trunk (mpg=rep78 foreign), savefirst
first
est store _ivreg2_price
ivreg2out _ivreg2_mpg _ivreg2_price
outreg2 using myfile, replace nor2 adds(r2, e(r2_1)) eqkeep(mpg)
outreg2 using myfile, nor2 adds(r2, e(r2_2)) eqkeep(price)
*** these are for the future reference (non-stacked)
* from stored estimates
sysuse auto, clear
ivreg2 price headroom trunk (mpg=rep78 foreign), savefirst
first
est store _ivreg2_price
outreg2 [*] using myfile, replace see
* cleaner column titles, can be used with ctitie( )
if so desired
sysuse auto, clear
ivreg2 price headroom trunk (mpg=rep78 foreign), savefirst
first
est store _ivreg2_price
est restore _ivreg2_mpg
outreg2 using myfile, replace
est restore _ivreg2_price
outreg2 using myfile, see
* by hand
sysuse auto, clear
reg mpg headroom trunk rep78 foreign
gen esample=e(sample)
outreg2 using myfile, replace
ivreg2 price headroom trunk (mpg=rep78 foreign) if e(sample), savefirst first
est store _ivreg2_price
outreg2 using myfile, see
See the following document for more options using outreg2
http://www.princeton.edu/~otorres/Outreg2.pdf
Publishing selected
variables
*******If
you do not see the menu on the left click here to see it
NOTE:
Replace words in italics with your own
use http://www.princeton.edu/~otorres/Panel101.dta
reg y x1 x2 x3
i.year i.country
matrix list e(b) /*This will allow you to see the names of the
coefficients*/
outreg2 using test, word keep(x2 1992.year
3.country)
*You will see
the following in blue
test.rtf /*If using PC click on this link, If using MAC find
the file ?test.rtf? and open it with Word*/
dir : seeout
See the following document for more options using outreg2
http://www.princeton.edu/~otorres/Outreg2.pdf