What is a linear regression?
A linear regression is used to predict the dependent variable using one or more independent variables.
Basically, we are seeing if the IV can predict changes in the DV.
This is different to correlation which just tells us whether there’s any relationship.
But…how does regression predict values?? Through the magical regression line. It’s not magical. I’m so tired right now – full uni day.
Anyway, cast your mind back to high school math. Do you remember this equation?
Yup. That’s the equation for a line! Remember how you could use this line to predict patterns like for every one increase in x, y will increase by a certain amount of units? This is exactly the model that regression works off.
When we plot all our x and y values with a line of best fit, we can begin to see potential patterns.
Great, but how do you actually do this in stata?
Ironically, running regression in stata is a piece of cake. The command is literally just: regress DV IV
The tricky part is all the assumption tests, because simple linear regressions have 4 assumptions they must meet.
Assumptions of Simple Linear Regression
- Independence of observations (All data points should be unrelated to each other.)
- Normal distribution of residuals (Errors should form a bell curve shape.)
- Homoscedasticity (Spread of errors should be consistent across all values.)
- Linearity (Relationship between X and Y should be roughly a straight line)
So let’s get started with the actual Stata stuff…
Checking Assumptions in Stata
Here are all the commands you will need to run your assumption checks for simple linear regression:
| Assumption | Stata Command | What you’re looking for (GOOD) | What’s BAD |
| Linearity | twoway (scatter DV IV) (lfit DV IV) | Points follow a roughly straight-line trend | Curved pattern (U-shape, exponential) |
| Homoscedasticity (constant variance) | rvfplot, yline(0) | Random cloud, even spread across plot | Funnel shape, widening/narrowing spread |
| Normality of residuals (visual) | histogram residuals, normal | Bell-shaped distribution | Skewed, heavy tails |
| Normality of residuals (plot) | pnorm residuals or qnorm residuals | Points close to straight line | Strong curve or deviation |
| Normality of residuals (test) | swilk residuals | p > .05 (normal enough) | p < .05 (not normal) |
| Independence of observations | estat dwatson (optional) | Value ~ 2 (no autocorrelation) | Far from 2 (autocorrelation) |
| No multicollinearity (only multiple regression) | vif | VIF < 5 (safe), < 10 acceptable | VIF > 10 (problematic) |
Here’s an example of what a set of met/good assumption checks would look like:
Homoscedasticity & linearity
Command used: rvfplot, yline(0)
Interpretation: You can see the graph below doesn’t show any weird fanning patterns (skinny or wide on one end). It looks like a nice even-ish spread.

Normality of residuals
Command used:histogram residuals, normal
Interpretation: Looks like a pretty good bell shape

Command used: pnorm residuals
Interpretation: We can see the points lie nicely around the line, so that’s good.

Command used: swilk residuals
Interpretation: This is just a final, trusty Shapiro Wilk test for normality. We can see the p value is > 0.05, so we fail to reject the null hypothesis and assume normality. Yay.

Running the Regression
Good news, the hard part is over. Now all you do is run this command:
regress DV IV
And you will get something that looks a bit like this:

Interpreting Results:
I’ve circled the most important bits of info you need.
The Prob > F = the p value. This tells you whether the test is statistically significant.
R-squared = your effect size.
_cons = the coefficient (y value when x=0)
P> t = p values for each IV
The coefficient values of your IV are like the slope of the line.
But what does it all mean?
Putting it together, we can see that there is a statistically significant positive relationship between the hours of research a student did and their project rating (p = 0.017). However, the model explains about 11.23% of the variability in project scores (R² = 0.112), suggesting a small effect size. We can also see that for every increase of 1 hour of research, the project’s score is predicted to rise by 1.36 points. Additionally, when no research hours are completed, the predicted project rating is 44.50.
And that’s all!