1.To test whether a sample mean is
different from a hypothesized value.
For example, for a sample of students you would expect an average SAT score of
1500 but for this specific sample you got, let’s say 1300. Giving the sample
size, the question becomes whether this sample score of 1300 is significantly
different from the expected value of 1500.

The general format is: ttest [variable] = [hypothesized value]

Example:ttestsatscore = 1500

Decision: if P>|t| or P>t are
lower than 0.05 then they are different.

2.To compare two sample means. Let’s say for example a pre-electoral
campaign poll in a city gave 35% of electoral preference to a particular
candidate. After the candidate’s visit to this city a similar post-electoral
campaign poll gave the same candidate a preference of 45%. To measure the
impact of the visit you want to see whether 35% differs statistically
significant from 45%.

The general format is: ttest [variable1] = [variable2]

Example:ttestpreferencepre = preferencepost

Decision: if P>|t| or P>t are
lower than 0.05 then they are different. The candidate’s visit may have had
some impact on his electoral preferences.

3.To compare two sample means by groups. For example you may want to see
whether males and females differ in their opinions regarding a particular topic
(for example, presidential agreement).

The general format is: ttest [variable], by([group
variable])

Example:ttest agree, by(gender)/*This assumes equal variances, standard
deviation for males is similar to sd for females*/

Example:ttest agree, by(gender) unequal/*Use this when sd
for males is quite different from that for females*/

Decision: if P>|t| or P>t are
lower than 0.05 then agreement with the president differs between males and
females.