Announcement

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

  • Add non-positive constraints to regression

    I am trying to constrain several regression coefficients to be non-positive (generally negative). How can I do this with either the nl or constraint commands? I find lots of advice for how to specify non-negative constraints, but not the opposite.

    For reference, here is what I have tried so far, which returns an error:

    constraint 1 inj1 < 0
    cnsreg hrql inj1, constraint(1)
    Last edited by Megan Sheahan; 14 Oct 2019, 14:54.

  • #2
    Are you running a linear regression? If so, check out

    Code:
    help cnsreg
    although zero would be okay
    But isn't constraining the coefficient to zero the same as omitting the variable from the regression?

    Comment


    • #3
      I did not notice your edit. You should always continue the thread if you are replying to someone.

      constraint 1 inj1 < 0
      This is not valid. Being that you say that you know how to constrain the coefficient of a variable to non-negative values, to constrain the coefficient of the same variable to be non-positive values, constrain the coefficient of (-1*variable) to non-negative values.

      Comment


      • #4
        Constraints can make perfect sense, but not to me on this evidence. You have a regression as simple as it could be, one response and one predictor and you want to force the coefficient to be negative, regardless? Something needs explaining here: is it a problem with outliers, marginal distributions, functional form, or something else? Why not show us

        Code:
        scatter hrql inj1
        and ideally explain what is going on and show example data too?

        Comment


        • #5
          Thank you for your helpful replies! Apologies for not providing more detail up front. The sample regression above is just a simplified version of what I am trying to estimate.

          I believe I solved my issue using the nl command. For reference if others have the same challenge, here is what I did (again, simplified):

          Code:
          nl (hrql = -exp({lna1})*inj1 + {c}), nolog
          nlcom (a1: exp(_b[lna1:_cons]))
          I believe that simply adding a negative sign in front of the output of the second line of code yields the constrained coefficients I'm looking for. It's possible, however, that I'm misinterpreting this output.

          Comment

          Working...
          X