Calculating t-test within categorical variable

Calculating t-test within categorical variable

by Melicent Peck -
Number of replies: 2

I'm trying to run the t-test between a continuous variable and categorical variable with 4 groups (coded 0, 1, 2, 3).  I only want to compare the continuous variable between groups 0-3; 1-3; 2-3.  I am having trouble with the command for this because I don't know how to tell Stata to only compare those groups. 

Thanks for any help!

In reply to Melicent Peck

Re: Calculating t-test within categorical variable

by Elizabeth Uy-Smith -

Hello Melicent, 

In order to specify which categories to include in the t-test, you need the "if" statement. For example in our coronary calcium dataset (age= continuous; caccat= categorized coronary calcium score): 

ttest age if caccat==1|caccat==2, by(caccat)

Hope that helps!

ellie

In reply to Elizabeth Uy-Smith

Re: Calculating t-test within categorical variable

by Melicent Peck -

Perfect!  Thanks so much.