Performs a statistical test as to whether a variable has a specified mean, whether two variables are equal, or whether the mean of one variable is equal across values of another variable.
Typical Use:
ttest varx = 2   - or -
ttest varx == vary, unpaired   - or -
ttest varx, by(groupvar)
. ttest male == 0.5
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
male | 1100 .5136364 .0150768 .5000414 .4840538 .543219
------------------------------------------------------------------------------
Degrees of freedom: 1099
Ho: mean(male) = 0.5
Ha: mean < 0.5 Ha: mean != 0.5 Ha: mean > 0.5
t = 0.9045 t = 0.9045 t = 0.9045
P < t = 0.8170 P > |t| = 0.3660 P > t = 0.1830
. ttest own_TV == own_bicycle, unpaired
Two-sample t test with equal variances
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
own_TV | 1098 .0801457 .0081978 .2716424 .0640606 .0962308
own_bi~e | 1098 .079235 .0081551 .2702282 .0632336 .0952363
---------+--------------------------------------------------------------------
combined | 2196 .0796903 .0057803 .2708749 .0683549 .0910258
---------+--------------------------------------------------------------------
diff | .0009107 .0115633 -.0217654 .0235869
------------------------------------------------------------------------------
Degrees of freedom: 2194
Ho: mean(own_TV) - mean(own_bicycle) = diff = 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
t = 0.0788 t = 0.0788 t = 0.0788
P < t = 0.5314 P > |t| = 0.9372 P > t = 0.4686
. ttest age, by(gender)
Two-sample t test with equal variances
------------------------------------------------------------------------------
Variable | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
---------+--------------------------------------------------------------------
male | 563 43.56838 .6611666 15.68791 42.26972 44.86704
female | 530 38.91698 .642816 14.79873 37.6542 40.17977
---------+--------------------------------------------------------------------
combined | 1093 41.3129 .466795 15.4325 40.39698 42.22882
---------+--------------------------------------------------------------------
diff | 4.651403 .9237718 2.838832 6.463973
------------------------------------------------------------------------------
Degrees of freedom: 1091
Ho: mean(male) - mean(female) = diff = 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
t = 5.0352 t = 5.0352 t = 5.0352
P < t = 1.0000 P > |t| = 0.0000 P > t = 0.0000
gen diff = varx - vary; ttest diff == 0;
. bitest male == 0.5
Variable | N Observed k Expected k Assumed p Observed p
-------------+------------------------------------------------------------
male | 1100 565 550 0.50000 0.51364
Pr(k >= 565) = 0.190959 (one-sided test)
Pr(k <= 565) = 0.825022 (one-sided test)
Pr(k <= 535 or k >= 565) = 0.381918 (two-sided test)
contact: djiboliz@gmail.com
last modified: 30 April 2007