# How to calculate sum of squared errors (SSE or SSR) with Stata 12 software?

I have a techincal issue with Stata: I need to calculate the SSE of a regression model, but the automatic output just gives me RMSE; I need SSE of this constrained model because I have to test if this model is better than the completely-free model.

SPSS gives me the SSE value in the regression output, but I don't know how to calculate a constrained linear regression with this model.

-
What command are you using? regress automatically displays a table with the sums of squares. –  andrea Sep 18 '12 at 14:16

If you are insane enough to literally try to compute the difference of the two sums of squares and relate it to an F distribution, you can certainly do that:

sysuse auto, clear
* (i) run full regression
regress price mpg foreign
* (ii) look into Stata guts
ereturn list
* (iii) take the pieces that you need
scalar ss_model_full = e(mss)
scalar dfres_full = e(df_r)
* (iv) run constrained regression
regress price foreign
scalar ss_model_constr = e(mss)
scalar dfres_constr = e(df_r)
* (v) construct the test statistic
scalar F = ( ss_model_full - ss_model_constr) / (ss_residual_full/dfres_full)
display scalar(F)
* (vi) relate it to its reference distribution
scalar p_F = Ftail( dfres_constr - dfres_full, dfres_full, F)
display scalar(p_F)


All the crap starting from (ii) is completely unnecessary and is fully taken care of with

test mpg
* look into the guts
return list


I would even go as far as to say that the reason they've written statistical software is that you won't have to do all the coding, introducing errors (statistical errors, code typos, references to wrong data, etc.) along the way.

-
I'm using the interface commands: Linear models > Constrained linear regression –  MatBi Sep 19 '12 at 9:26
Wow. Never used Stata interface in 15 years of working with Stata on a daily basis :). So what kind of constraints do you deal with? Constrained regression in Stata is meant to deal with linear constraints of the form $\beta_1 + \beta_2 = 1, \beta_3 = \beta_4 - \beta_5$ and the like. You can test these constraints with test, too, following the encompassing unconstrained regression. If your constraints are $\beta_1=0$, then that's equivalent to incuding/excluding variables from regression equation, and that's what I described above. –  StasK Sep 19 '12 at 19:11
My constraint is: beta1 + beta4 - beta2 - beta3=0 –  MatBi Sep 20 '12 at 12:37
Just test it, then. –  StasK Sep 21 '12 at 3:55
I've tested the hypothesis with the test command; bytheway, the alternative hypothesis used is symmetric; I need an asymmetric alternative hypothesis, how can i do? –  MatBi Oct 3 '12 at 8:55