I currently struggle to apply the reverse option to my ttest .
Here is a toy example:
sysuse auto,clear
local varlist mpg price weight
eststo foreign: quietly estpost summarize `varlist' if foreign==0
eststo domestic: quietly estpost summarize `varlist' if foreign==1
eststo diff: quietly estpost ttest mpg, by(foreign) unequal **reverse**
esttab foreign domestic diff
The following works:
sysuse auto,clear
local varlist mpg price weight
eststo foreign: quietly estpost summarize `varlist' if foreign==0
eststo domestic: quietly estpost summarize `varlist' if foreign==1
eststo diff: quietly estpost ttest mpg, by(foreign) unequal reverse
esttab foreign domestic diff
Note:
ttest mpg, by(foreign) unequal reverse
works.
After reading the estpost documentation, it seems the package currently does not support the option.
Eventually, I need to create a table of ttests for about 20 variables and reverse the result for b/t. I'm vey thankful for workarounds!
You can do everything using regression like this (even in small samples):
. sysuse auto, clear
(1978 automobile data)
. /* reverse t-test */
. ttest mpg, by(foreign) unequal reverse
Two-sample t test with unequal variances
------------------------------------------------------------------------------
Group | Obs Mean Std. err. Std. dev. [95% conf. interval]
---------+--------------------------------------------------------------------
Foreign | 22 24.77273 1.40951 6.611187 21.84149 27.70396
Domestic | 52 19.82692 .657777 4.743297 18.50638 21.14747
---------+--------------------------------------------------------------------
Combined | 74 21.2973 .6725511 5.785503 19.9569 22.63769
---------+--------------------------------------------------------------------
diff | 4.945804 1.555438 1.771556 8.120053
------------------------------------------------------------------------------
diff = mean(Foreign) - mean(Domestic) t = 3.1797
H0: diff = 0 Satterthwaite's degrees of freedom = 30.5463
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
Pr(T < t) = 0.9983 Pr(|T| > |t|) = 0.0034 Pr(T > t) = 0.0017
. /* calculate means */
. eststo means: qui reg mpg ibn.foreign, vce(hc2) nocons
. /* regression equivalent using robust veriance with a bias correction and t-test DoF */
. eststo diff: qui margins, dydx(foreign) df(`=scalar(df_t)') post
. esttab means diff, label se
----------------------------------------------------
(1) (2)
Mileage (m~)
----------------------------------------------------
Domestic 19.83*** 0
(0.658) (.)
Foreign 24.77*** 4.946**
(1.410) (1.555)
----------------------------------------------------
Observations 74 74
----------------------------------------------------
Standard errors in parentheses
* p<0.05, ** p<0.01, *** p<0.001
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.