Announcement

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

  • constraint

    Hi All,

    I am running a restricted regression but the constraint wouldn't work and I can't tell what I am missing between the lines
    Below is what i have done so far

    y = b0 + b1X1 + b2X2 + b3X3

    constraint 1 b1+b2+b3 = 1

    reg y X1 X2 X3, c(1)

    How ever, it never worked. Something seems to be wrong with the constraint or I cannot have a constraint as such?

    Thanks
    Francis

  • #2
    -regress- does not support constraints. You need -cnsreg- for that.

    That said, showing model equations isn't really helpful. You need to show the actual code involved. For it is possible that there are other errors in the way you formulate the constraint, etc., so that even -cnsreg- might not work with it. For example b1 + b2 + b3 = 1 is neither syntactically correct nor meaningful to the -constraint- command. So you need to show exactly how you did it.

    Another, often simpler approach, to constrained regressions is to use -test, coef- to impose the constraint. For example:

    Code:
    sysuse auto, clear
    regress price mpg headroom trunk length
    test trunk - length = 60, coef

    Also saying something "never worked" isn't very helpful either--that could mean almost anything. Instead, show the output you got from Stata and, unless it's obvious, say how it differs from what you were expecting.

    More generally, please read the entire Forum FAQ for excellent advice on how to post in ways that maximize your chances of getting timely, helpful responses.
    Last edited by Clyde Schechter; 07 Oct 2017, 16:15.

    Comment


    • #3
      I agree with everything Clyde said. Taking his test suggestion a bit further, is this the sort of thing you want?

      Code:
      . webuse nhanes2f, clear
      
      . reg health female black diabetes
      
            Source |       SS           df       MS      Number of obs   =    10,335
      -------------+----------------------------------   F(3, 10331)     =    206.18
             Model |  849.323219         3   283.10774   Prob > F        =    0.0000
          Residual |  14185.6982    10,331  1.37311956   R-squared       =    0.0565
      -------------+----------------------------------   Adj R-squared   =    0.0562
             Total |  15035.0214    10,334   1.4549082   Root MSE        =    1.1718
      
      ------------------------------------------------------------------------------
            health |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            female |  -.0658891   .0230867    -2.85   0.004    -.1111435   -.0206346
             black |  -.4661333   .0376353   -12.39   0.000    -.5399059   -.3923607
          diabetes |  -1.112933   .0538453   -20.67   0.000     -1.21848   -1.007385
             _cons |   3.551145   .0172967   205.31   0.000     3.517241     3.58505
      ------------------------------------------------------------------------------
      
      . test female + black + diabetes = 1, coef
      
       ( 1)  female + black + diabetes = 1
      
             F(  1, 10331) = 1524.30
                  Prob > F =    0.0000
      
      
      Constrained coefficients
      
      ------------------------------------------------------------------------------
                   |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            female |   .2240844   .0218594    10.25   0.000     .1812408    .2669281
             black |   .2880849   .0322991     8.92   0.000     .2247797      .35139
          diabetes |   .4878307   .0349035    13.98   0.000     .4194211    .5562403
             _cons |   3.242364   .0153826   210.78   0.000     3.212214    3.272513
      ------------------------------------------------------------------------------
      Your original idea would work too but, as Clyde says, the constraint syntax is wrong and you need to cnsreg:

      Code:
      . constraint 1 female + black + diabetes = 1
      
      . cnsreg health female black diabetes, c(1)
      
      Constrained linear regression                   Number of obs     =     10,335
                                                      Root MSE          =     1.2552
      
       ( 1)  female + black + diabetes = 1
      ------------------------------------------------------------------------------
            health |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            female |   .2240844   .0234154     9.57   0.000     .1781856    .2699832
             black |   .2880849   .0345983     8.33   0.000     .2202655    .3559043
          diabetes |   .4878307   .0373881    13.05   0.000     .4145429    .5611186
             _cons |   3.242364   .0164776   196.77   0.000     3.210065    3.274663
      ------------------------------------------------------------------------------
      I think the differences in SEs has to do with whether you impose constraints before estimation or after.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Thanks so much everybody, I will cross check my syntax and post appropriately if my corrections don't work

        Comment


        • #5
          For good measure you can set this up as a lrtest of nested models:

          Code:
          webuse nhanes2f, clear
          reg health female weight height
          est store unconstrained
          constraint 1 female + weight + height = 1
          cnsreg health female weight height, c(1)
          est store constrained
          lrtest unconstrained constrained, force
          Or,

          Code:
          webuse nhanes2f, clear
          glm health female weight height
          est store unconstrained
          constraint 1 female + weight + height = 1
          glm health female weight height, constraint(1)
          est store constrained
          lrtest unconstrained constrained
          EDIT: I changed the variables in my different examples but hopefully you get the idea.
          Last edited by Richard Williams; 07 Oct 2017, 18:51.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment


          • #6
            I'm really grateful Richard. I have really learnt a lot from all the helps so far.

            Comment

            Working...
            X