Hello everyone,

I have a really basic question about Stata calculations for the -reg- command. I have read the manual and searched on this forum, but I cannot seem to find an answer, and I'm hoping someone can provide a quick clarification for me. When I use -reg- for a simple regression, the reported Residual Sum of Squares (RSS) does not equal the same value as when I calculate this manually in Stata version 15.1. For example, I'll use the internal auto.dta dataset to show the issue I am having. I will do a simple regression with price as the outcome variable and mpg as the predictor variable. The calculated RSS shows up as 495615923.

Code:
sysuse auto
reg price mpg
But, when I calculate this manually using -predict-, I get a value of 495615916. I do this by using the -predict- command (with -xb- option) to generate predicted values of y (which I call yhat). I then generate a variable called residual that equals price (y) minus yhat. Then I generate residual_2, which is residual squared. Then, I use the -total- command to find the sum of all the squared residuals (and use -matrix results- and -display- with %11.0g formatting to display the value without scientific notation.)

Code:
reg price mpg
predict yhat, xb
gen residual = price - yhat
gen residual_2 = residual^2

total(residual_2)
matrix results = e(b)
di %11.0g results[1,1]
I also calculate this using a third method, where I use -predict- with the option -residual-, and then use the same steps as the above manual calculation. With this method, I get another different value; this time it's 495615910.

Code:
reg price mpg
predict resid, residuals
gen resid_2 = resid^2

total(resid_2)
matrix results = e(b)
di %11.0g results[1,1]
Does anyone know why the two manual methods I use for calculating RSS does not match the value reported when I use the -reg- command? Which of the three values should I use reporting results? Last, does anyone know the code for how to manually calculate the value of RSS that will match the output value in the -reg- command?

Thanks for everyone's help with this (hopefully straightforward) clarification.

Best,
Thomas