Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Find Constrained linear regression's Residual Sum of Squares [SSE

    I wrote a program to calculate AIC [Akaike] and SC [Schwarz] for regression model, the program works well but when it come to Constrained linear regression model, problem started to pop up: the Constrained linear regression command in stata doesn't return e(rss) for me to use to calculate AIC and SC.

    So any ideals how to calculate SSE in Constrained linear regression model.
    Thank you
    *---
    *(c)
    *---
    constraint 1 beds = 0
    constraint 2 c.livarea#c.livarea#c.beds = 0
    constraint 3 c.age#c.beds = 0
    constraint 4 c.age#c.age#c.beds = 0
    cnsreg lsprice livarea c.livare#c.livarea age c.age#c.age beds c.livarea#c.beds c.livarea#c.livarea#c.beds c.age#c.beds c.age#c.age#c.beds, c(1 2 3 4)


    *---
    *(d)
    *---
    *Program for calculating AIC and SC
    program crical
    scalar AIC= ln(e(rss)/e(N))+ (2*e(rank))/e(N)
    scalar SC = ln(e(rss)/e(N))+ (e(rank)*ln(e(N)))/e(N)
    di in red "R-squared: " e(r2) _n ///
    "R-adjsted: " e(r2_a)
    scalar list AIC SC
    end

    Result:
    . crical
    R-squared: .
    R-adjsted: .
    AIC = .
    SC = .




  • #2
    Unless there's a reason, other than scaling, to use different formulas for AIC and BIC, you could use Stata's estat ic

    Code:
    sysuse auto, clear
    reg price mpg turn
    estat ic
    constraint 1 turn=1
    cnsreg price mpg turn, c(1)
    estat ic
    Jorge Eduardo Pérez Pérez
    www.jorgeperezperez.com

    Comment


    • #3
      Originally posted by Jorge Eduardo Perez Perez View Post
      Unless there's a reason, other than scaling, to use different formulas for AIC and BIC, you could use Stata's estat ic

      Code:
      sysuse auto, clear
      reg price mpg turn
      estat ic
      constraint 1 turn=1
      cnsreg price mpg turn, c(1)
      estat ic
      Thank you, i was trying to replicate the formula in an econometrics textbook to illustrate the different between using AIC and SC for small data and large data.
      So any ideal how to compute SSE for the constraint linear regression model in STATA? There a way to get around is too manually substitute the constraint into the original model then regress normally but it would take a lot of time
      Last edited by Định Nguyễn; 03 Aug 2015, 03:34.

      Comment


      • #4
        cnsreg doesn't return the sum of squares for residuals(SSR), also called the SSE ("sum of squares for error". But it does return the square root of the mean square error, commonly abbreviated "RMSE" in e(rmse). You could have computed SSE from that and from other returned values:

        Code:
        sysuse auto, clear
        constraint 1 price = weight
        constraint 2 gear_ratio = -foreign
        constraint 3 displ = weight
        
        
        cnsreg mpg price weight displ gear_ratio foreign length headroom, ///
         c(1-3) vce(robust)
        ereturn list
        matrix C = e(Cns)
        matrix b = e(b)
        /*  See formula for MSE last page of manual entry for cnsreg */
        local n = e(N)
        local p = colsof(b) // no. of coefficients
        local c = rowsof(C) // no. of constraints
        local sse = (`n'-`p'+`c')*e(rmse)^2
        di `sse'
        
        /* However  p-c = rank of e(V), so
        a short formula is */
        local sse = (e(N)-e(rank))*e(rmse)^2
        di `sse'

        Steve Samuels
        Statistical Consulting
        [email protected]

        Stata 14.2

        Comment

        Working...
        X