Home › Statistics Homework Help › STATA Homework Help
Run it, read it, report it

STATA Homework Help

This page shows you how to run the common tests in Stata, which number in the output actually matters, and how to write the result in APA. When the deadline is tight or the data will not behave, a statistician can run and interpret it on your own file.

✓Correct output, read the right line ✓Copy-paste APA reporting ✓Human statisticians, no AI

Tests covered on this page

Independent t-testPaired t-testOne-way ANOVA Bonferroni post-hocChi-squarePearson correlation Non-parametric fallbacksAssumption checksAPA reporting
Since 2014statistics specialists
Any testrun and interpreted
★★★★★rated by students
3 hrsfastest turnaround

Stata is less about memorising syntax than knowing which command fits the design and what the output means. Pick the wrong test, skip the assumption checks, or read the wrong line of the results, and the analysis is wrong no matter how tidy the do-file looks. This guide is part of our statistics homework help. It gives the exact command for each common test, points at the one value in the output that decides the result, and shows how to report it. Where a test can fail, it names the check and the fallback command to use instead. If you would rather hand the file over, our team can do your Stata homework end to end.

One habit that saves marks. Type your commands into a do-file rather than the Command window, so every step is saved, repeatable and easy to correct. Stata reads a command the same way whether you run it once or a hundred times, and a do-file is the record your grader and your future self can follow.

Which test do I need?

Match your research question and variable types to the right command, then jump to its guide.

Your questionYour dataTest
Do two unrelated groups differ on average?Continuous outcome, two independent groupsIndependent-samples t-test
Did the same people change between two points?Continuous outcome, two paired measuresPaired-samples t-test
Do three or more unrelated groups differ?Continuous outcome, three or more groupsOne-way ANOVA
Are two categories associated?Two categorical variablesChi-square test of independence
Do two continuous variables move together?Two continuous variablesPearson correlation

Not sure your data meets the requirements? Every guide below lists the assumptions and the command to switch to when one fails.

Getting started in Stata: the windows, loading data and encoding categories

Stata runs on typed commands, and there are two ways to enter them. The Command window at the bottom of the screen runs one line at a time, which is handy for a quick look. For an assignment you should work in a do-file instead: open the Do-file Editor, type your commands in order, and run them as a block. The do-file is saved, so you can rerun the whole analysis, fix one line and repeat it, or hand it in as proof of your steps. Everything Stata prints back appears in the Results window, and each command you run is echoed there with a dot in front of it, so the log reads as command then output, command then output.

To get your data in, the command depends on the file type. For a CSV or other delimited text file use import delimited "yourfile.csv", clear. For a native Stata .dta file use use "yourfile.dta", clear. The clear option tells Stata to drop whatever is already in memory first. After loading, run describe to see the variables and their storage types, and codebook or summarize to check the values.

The setting that quietly breaks analyses is how a category is stored. A grouping variable read in as text, for example a sex column holding the words "male" and "female", is a string, and most modelling commands will not accept a string. Convert it to a labelled numeric variable with encode sex, generate(sexn). Stata then stores one and two under the hood but shows the words in your output through value labels. If a category was read in as a bare number with no labels, attach them yourself: label define sexlbl 1 "Male" 2 "Female", then label values sexn sexlbl. Labelled categories make the output readable and stop you from treating a code as a real quantity.

How to run the common tests in Stata

The command, the assumption checks, the exact number to read, and how to report it. Example values follow standard teaching datasets.

Independent-samples t-test in Stata

Compares the means of one continuous outcome across two unrelated groups.

Command: ttest y, by(group). Here y is the continuous outcome and group is the two-category grouping variable. If the two groups have unequal spread, add the unequal option for Welch's version.

Assumptions. Continuous outcome, two independent groups, no serious outliers, approximate normality within each group (check with swilk y if group==0 and again for the other group), and equal variances. Stata does not fold a variance test into ttest, so test it separately with robvar y, by(group) or read Bartlett's test from oneway y group. If variances differ, rerun with ttest y, by(group) unequal. If normality is badly broken, switch to the Mann-Whitney test with ranksum y, by(group).

What to read. The t statistic is on the right of the table, on the line that ends t = . The degrees of freedom sit just below it. Stata then prints three probabilities, one per alternative hypothesis. For an ordinary non-directional test read the middle one, Ha: diff != 0 with Pr(|T| > |t|). That is your two-sided p-value.

. ttest y, by(group)
. ttest y, by(group) Two-sample t test with equal variances ------------------------------------------------------------------------------ Group | Obs Mean Std. err. Std. dev. [95% conf. interval] ---------+-------------------------------------------------------------------- 0 | 20 5.80 .0857 .383 5.621 5.979 1 | 20 6.15 .1163 .520 5.907 6.393 ---------+-------------------------------------------------------------------- diff | -.35 .1442 -.6419 -.0581 ------------------------------------------------------------------------------ diff = mean(0) - mean(1) t = -2.4280 Ho: diff = 0 Degrees of freedom = 38 Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 Pr(T < t) = 0.0101 Pr(|T| > |t|) = 0.0203 Pr(T > t) = 0.9899
Report it (APA)Cholesterol concentration was significantly lower after exercise training (M = 5.80, SD = 0.38) than after a calorie-controlled diet (M = 6.15, SD = 0.52), t(38) = 2.43, p = .020.

Common mistakes

  • Reading a one-sided probability, Pr(T < t) or Pr(T > t), when the hypothesis is non-directional. Report the middle value.
  • Assuming equal variances without checking, then reporting the wrong standard error and p-value. Test it, and add unequal when needed.
  • Passing a string grouping variable, which Stata rejects. Encode it to a labelled numeric first.

Unequal variances, outliers, or a non-normal outcome on your own dataset? Our statisticians will run the correct version and interpret it. Get a quote →

Paired-samples t-test in Stata

Compares two measurements taken on the same people, for example a score before and after training.

Command: ttest before == after. The two variables hold the two measurements for each person, stored in the same row.

Assumptions. A continuous outcome measured twice on the same cases, no serious outliers, and normality of the difference scores, not the raw variables. Build the difference with generate diff = before - after, then check it with swilk diff and a boxplot. If the differences are badly non-normal, use the Wilcoxon signed-rank test with signrank before == after.

What to read. The t statistic is again on the line that ends t = , and the degrees of freedom equal the number of pairs minus one. Read the same middle probability, Pr(|T| > |t|), for the two-sided p-value.

. ttest before == after
. ttest before == after Paired t test ------------------------------------------------------------------------------ Variable | Obs Mean Std. err. Std. dev. [95% conf. interval] ---------+-------------------------------------------------------------------- before | 20 2.48 .0358 .160 2.405 2.555 after | 20 2.52 .0358 .160 2.445 2.595 ---------+-------------------------------------------------------------------- diff | 20 -.04 .0084 .0375 -.0576 -.0224 ------------------------------------------------------------------------------ mean(diff) = mean(before - after) t = -4.7730 Ho: mean(diff) = 0 Degrees of freedom = 19 Ha: mean(diff) < 0 Ha: mean(diff) != 0 Ha: mean(diff) > 0 Pr(T < t) = 0.0001 Pr(|T| > |t|) = 0.0001 Pr(T > t) = 0.9999
Report it (APA)There was a significant improvement in jump distance after plyometric training, from before (M = 2.48, SD = 0.16) to after (M = 2.52, SD = 0.16), t(19) = 4.77, p < .001.

Common mistakes

  • Running a paired test on unrelated groups, which needs ttest y, by(group) instead.
  • Testing normality on the raw scores instead of the difference scores.
  • Reporting p = 0.0000 as printed. A probability is never zero, so write p < .001.

One-way ANOVA with Bonferroni post-hoc in Stata

Compares the means of one continuous outcome across three or more unrelated groups.

Command: oneway y group, tabulate bonferroni. The tabulate option adds a table of group means, and bonferroni adds the pairwise post-hoc comparisons. You can fit the same model with anova y group, which is the route to use when you later add a second factor, an interaction or a covariate.

Assumptions. Continuous outcome, three or more independent groups, no serious outliers, normality within groups (swilk on the residuals or within each group), and equal variances. The oneway command prints Bartlett's test for equal variances at the foot of the table. If Bartlett's is significant, the equal-variance assumption is broken, so treat the result with care and consider a Welch-style analysis or the Kruskal-Wallis test kwallis y, by(group).

What to read. In the analysis of variance table read the Between groups row for the F ratio, and the Prob > F column for the p-value. Then read the Bonferroni matrix below it, where each cell gives the mean difference and, in brackets, the adjusted p-value for that pair.

. oneway y group, tabulate bonferroni
. oneway y group, tabulate bonferroni Analysis of variance Source SS df MS F Prob > F ------------------------------------------------------------------------ Between groups 85.500 2 42.7500 4.47 0.0212 Within groups 258.300 27 9.5667 ------------------------------------------------------------------------ Total 343.800 29 11.8552 Bartlett's test for equal variances: chi2(2) = 1.3210 Prob>chi2 = 0.517
Report it (APA)Completion time differed significantly across course levels, F(2, 27) = 4.47, p = .021. Bonferroni post-hoc comparisons showed the beginner group was significantly slower than the intermediate (p = .046) and advanced (p = .034) groups, which did not differ from each other (p = .989).

Common mistakes

  • Reporting only the omnibus F without the post-hoc comparisons that show which groups differ.
  • Ignoring a significant Bartlett's test and reporting the standard ANOVA anyway.
  • Using a between-groups ANOVA on repeated measures from the same people.

Unequal variances or a messy multi-group design on your own file? Send it and we will run it, apply the right correction, and write the result. Get a quote →

Chi-square test of independence in Stata

Tests whether two categorical variables are associated, for example gender and a preferred learning format.

Command: tabulate a b, chi2. Add expected to print expected counts, and column or row for percentages. For a two-by-two table with small counts add exact for Fisher's exact test.

Assumptions. Both variables categorical, independent observations, and expected counts large enough: no more than 20 percent of cells may have an expected count below five. Print the expected counts with tabulate a b, chi2 expected and check them. If the rule fails in a two-by-two table, read the Fisher's exact p-value from tabulate a b, exact.

What to read. Below the crosstab Stata prints one line: Pearson chi2(df) = value and Pr = p. The value is the statistic, df is the degrees of freedom, and Pr is the p-value.

. tabulate a b, chi2
. tabulate a b, chi2 | b a | 0 1 | Total -----------+----------------------+---------- 0 | 16 9 | 25 1 | 13 12 | 25 -----------+----------------------+---------- Total | 29 21 | 50 Pearson chi2(1) = 0.4870 Pr = 0.485
Report it (APA)There was no statistically significant association between gender and preferred learning medium, χ²(1) = 0.49, p = .485.

Common mistakes

  • Reporting the chi-square while more than 20 percent of cells have expected counts below five, instead of switching to Fisher's exact test.
  • Using it on paired categorical data, for example the same people before and after, which needs McNemar's test through mcc.
  • Claiming the test shows causation. It shows association only.

Pearson correlation in Stata

Measures the strength and direction of the linear relationship between two continuous variables.

Command: pwcorr x y, sig. The sig option prints the p-value under each coefficient. Plain correlate x y gives the coefficient only, with no p-value, so use pwcorr with sig when you need to report significance.

Assumptions. Two continuous variables, a linear relationship and no serious outliers, both checked on a scatterplot (scatter y x) before you trust the coefficient, and approximate normality. Pearson only captures linear association, so a strong curved relationship can still return a small r. For ordinal data or a monotonic but non-linear relationship, use Spearman with spearman x y.

What to read. The output is a matrix with ones on the diagonal. Read an off-diagonal cell: the top number is r, from minus one to plus one, and the number below it, printed by the sig option, is the two-sided p-value.

. pwcorr height jump, sig
. pwcorr height jump, sig | height jump -------------+------------------ height | 1.0000 | | jump | 0.7060 1.0000 | 0.0047
Report it (APA)There was a strong, positive, statistically significant correlation between height and jump distance, r = .71, n = 14, p = .005.

Common mistakes

  • Reporting correlate output as significant when it prints no p-value at all. Use pwcorr x y, sig.
  • Skipping the scatterplot, so a curved pattern or an outlier is missed.
  • Treating correlation as proof of causation.

When an assumption fails: the fallback command

Most Stata marks are lost not on the software but on ignoring a broken assumption. Check the assumption, and when it fails, switch to the matched non-parametric command rather than reporting an invalid result.

Parametric testAssumption that failsNon-parametric fallback in Stata
Independent t-testNormality within groupsMann-Whitney: ranksum y, by(group)
Paired t-testNormality of the differencesWilcoxon signed-rank: signrank before == after
One-way ANOVANormality or equal variancesKruskal-Wallis: kwallis y, by(group)
Pearson correlationLinearity or normalitySpearman: spearman x y
Chi-squareExpected cell counts too smallFisher's exact: tabulate a b, exact

Reading Stata output: the mistakes that change the grade

Procedures on this page were checked against the Stata official documentation and manuals and the UCLA statistical computing Stata guides.

Or run it with a statistician

When the data will not behave, an assumption fails, or the deadline is unforgiving, a specialist runs it in Stata on your file and explains the output so you can defend it. This is done-with-you help: you keep the do-file and the interpretation, and you understand every step.

What one order includes: the right test chosen for your design, run in Stata on your data, the correct output, a plain-language interpretation, and the result written in your required reporting style. A do-file is included so the analysis is reproducible.
1

Send your Stata task

Upload your data file, the assignment brief and your deadline, then get a free quote from support.

2

Pay securely

Approve the price and a statistician who works in Stata every day starts right away.

3

Download the analysis

Get the output, interpretation and write-up in your account, with free revisions if you need them.

Vetted and safe

Real statisticians, and your data protected

Your work goes to a specialist who passed a subject-specific statistics test and a background check, and who works in Stata every day. What we deliver is a model answer and study aid for reference, and many students use it to learn the method and check their own analysis.

Everything stays private. Your data and details are confidential, we never contact your school, payments are secure, and the work is original and plagiarism-checked.

Get Stata help you can trust →

Every order includes

Right test for the designOutput and interpretation Do-file included100% human, no AI Data kept confidentialFree revisions
★★★★★
What students say
★★★★★

"I was a little skeptical at first but this is definitely the best decision I could have made when it comes to getting help with my homework. This is a legit business and the staff are very helpful and professional."

Kennedy C.
Verified review
★★★★★

"Very good and friendly customer service. Most importantly give great results on time. Im very I chose homeworkdoer to do work for me. Excellent service."

Panos X.
Verified review

Stata homework FAQ

For two unrelated groups type ttest y, by(group), where y is the continuous outcome and group holds the two codes. For two measurements on the same people type ttest before == after. Stata prints the t statistic on the line that ends t = , and the two-sided p-value on the middle probability line, Pr(|T| > |t|).

Stata prints three probabilities under the ttest table, one for each alternative hypothesis. The middle one, Ha: diff != 0 with Pr(|T| > |t|), is the two-sided p-value you report for an ordinary non-directional hypothesis. If it is below your alpha, usually 0.05, the result is statistically significant. The left and right values are one-sided p-values for directional hypotheses.

Both fit a one-way analysis of variance. The oneway command is the quicker route for a single factor and adds Bartlett's test for equal variances plus built-in Bonferroni, Sidak and Scheffe post-hoc comparisons. The anova command is the general model command that also handles two or more factors, interactions and covariates, with comparisons run afterward through pwcompare or margins. For a single grouping variable oneway is usually enough.

Run tabulate a b, chi2. Under the crosstab Stata prints Pearson chi2(df) = value and Pr = p. The value is the test statistic, df is the degrees of freedom, and Pr is the p-value. Add the expected option to check the expected counts, and add exact for Fisher's exact test in small two-by-two tables.

When normality is badly broken or the outcome is ordinal, switch to the matched command: ranksum for the Mann-Whitney equivalent of an independent t-test, signrank for the Wilcoxon equivalent of a paired t-test, kwallis for the Kruskal-Wallis equivalent of one-way ANOVA, and spearman in place of Pearson correlation.

Yes. Send your data set and the assignment and a statistician runs the analysis in Stata, reports the output and interprets it in full, before your deadline, with free revisions. A do-file is included so the analysis is reproducible.

Every task gets a custom quote based on the analysis, length and your deadline. Send the details and you see a free, no-obligation price before you pay anything.

Get your Stata done right

Hand it to a statistician and get accurate output and a clear interpretation before your deadline.

Get my free quote →

Related homework help

We use cookies to improve your experience. See our cookie policy.