Hi All!
The previous -for- command would do this:
.. for varlist var1 var2: ttest X, by(group)
-> ttest var1, by(group)
Two-sample t test with equal variances
------------------------------------------------------------------------
------
Group | Obs Mean Std. Err. Std. Dev. [95% Conf.
Interval]
---------+--------------------------------------------------------------
------
Controls | 53 4.373019 .4801821 3.495779 3.409463
5.336575
Cases | 52 6.741923 .7373028 5.316766 5.261726
8.22212
---------+--------------------------------------------------------------
------
combined | 105 5.54619 .4513336 4.624793 4.651179
6.441202
---------+--------------------------------------------------------------
------
diff | -2.368904 .8765335 -4.107302
-.6305068
------------------------------------------------------------------------
------
Degrees of freedom: 103
Ho: mean(Controls) - mean(Cases) = diff = 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
t = -2.7026 t = -2.7026 t =
-2.7026
P < t = 0.0040 P > |t| = 0.0080 P > t =
0.9960
-> ttest var2, by(group)
Two-sample t test with equal variances
------------------------------------------------------------------------
------
Group | Obs Mean Std. Err. Std. Dev. [95% Conf.
Interval]
---------+--------------------------------------------------------------
------
Controls | 39 .4102564 .1672108 1.044231 .0717559
..7487569
Cases | 37 2.121622 .6984016 4.248211 .7051975
3.538046
---------+--------------------------------------------------------------
------
combined | 76 1.243421 .3619505 3.155412 .5223786
1.964463
---------+--------------------------------------------------------------
------
diff | -1.711365 .701359 -3.108853
-.313877
------------------------------------------------------------------------
------
Degrees of freedom: 74
Ho: mean(Controls) - mean(Cases) = diff = 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
t = -2.4401 t = -2.4401 t =
-2.4401
P < t = 0.0085 P > |t| = 0.0171 P > t =
0.9915
The new -foreach- command does this:
Two-sample t test with equal variances
------------------------------------------------------------------------
------
Group | Obs Mean Std. Err. Std. Dev. [95% Conf.
Interval]
---------+--------------------------------------------------------------
------
Controls | 53 4.373019 .4801821 3.495779 3.409463
5.336575
Cases | 52 6.741923 .7373028 5.316766 5.261726
8.22212
---------+--------------------------------------------------------------
------
combined | 105 5.54619 .4513336 4.624793 4.651179
6.441202
---------+--------------------------------------------------------------
------
diff | -2.368904 .8765335 -4.107302
-.6305068
------------------------------------------------------------------------
------
Degrees of freedom: 103
Ho: mean(Controls) - mean(Cases) = diff = 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
t = -2.7026 t = -2.7026 t =
-2.7026
P < t = 0.0040 P > |t| = 0.0080 P > t =
0.9960
Two-sample t test with equal variances
------------------------------------------------------------------------
------
Group | Obs Mean Std. Err. Std. Dev. [95% Conf.
Interval]
---------+--------------------------------------------------------------
------
Controls | 39 .4102564 .1672108 1.044231 .0717559
..7487569
Cases | 37 2.121622 .6984016 4.248211 .7051975
3.538046
---------+--------------------------------------------------------------
------
combined | 76 1.243421 .3619505 3.155412 .5223786
1.964463
---------+--------------------------------------------------------------
------
diff | -1.711365 .701359 -3.108853
-.313877
------------------------------------------------------------------------
------
Degrees of freedom: 74
Ho: mean(Controls) - mean(Cases) = diff = 0
Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
t = -2.4401 t = -2.4401 t =
-2.4401
P < t = 0.0085 P > |t| = 0.0171 P > t =
0.9915
Note that you lose any sense of what the dependent variable is. Instead,
the log simply lists t-test after t-test. Is there any way we can bring
back some marker of the command Stata repeats?
Thanks,
Elmer
************************************************
Elmer V Villanueva, MD ScM
Senior Research Fellow
Monash Institute of Health Services Research
Level 1, Block E
Monash Medical Centre
246 Clayton Road, Clayton
Victoria 3168 Australia
Tel: (+61 3) 9594 7545
Fax: (+61 3) 9594 7554
Mob: 0439 947 544
Email: [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/