Announcement

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

  • Getting constraints right with cnsreg

    Hi everyone,

    This might turn out to have a simple answer, but I'm struggling with how to impose some constraints in an application of mine. In brief, I derive an equilibrium condition that I want to take to the data. I specifically have an equation of the form:

    ln(y) = nu*ln(x1) + [alpha*(1-gamma) - 1]*ln(x2) + (1-alpha)*(1-gamma)*ln(x3)

    Normally (and what I tried) is just taking the sum of the coefficients on ln(x2) and ln(x3). Doing so produces: -gamma. Ideally, I'd like it to have produced 0 so that I can write:
    constr def 1 ln(x2) + ln(x3) = 0

    Does anyone see a way for me to manipulate the expressions or insert another type of constraint?

    Thank you!

  • #2
    Well, what is the problem? What went wrong when you tried it? It seems you should be able to do this quite easily:

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . constraint define 1 weight + length = 0
    
    . cnsreg price mpg weight length, constraint(1)
    
    Constrained linear regression                   Number of obs     =         74
                                                    F(   2,     71)   =      14.90
                                                    Prob > F          =     0.0000
                                                    Root MSE          =  2510.1423
    
     ( 1)  weight + length = 0
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |   -47.4023   85.82747    -0.55   0.582    -218.5374    123.7328
          weight |   1.817349   .6566766     2.77   0.007     .5079732    3.126725
          length |  -1.817349   .6566766    -2.77   0.007    -3.126725   -.5079732
           _cons |   2028.925   3516.223     0.58   0.566    -4982.226    9040.075
    ------------------------------------------------------------------------------
    Why don't you show us exactly what you tried and exactly what Stata responded with, and maybe we can troubleshoot it for you. Please do that by copying from the Results window or from your log file and pasting into a code block on this Forum. (See FAQ #12 if you don't know how to set up a code block.) Please do not retype anything, because the devil is usually in the details and its easy to unwittingly change small details when retyping.

    By the way, when I add up the coefficients of x2 and x3 in your model, I get 1-gamma, not -gamma.

    Comment


    • #3
      Hey Clyde,

      Thanks for the reply. The reason I didn't copy any stata output was because I wasn't sure how to set the constraint. In the example above, the sum of the two coefficients equals a known constant, whereas in my case it equals an unknown function of parameters (1-gamma). I think the issue is that gamma and alpha are not separately identified, but I wasn't sure if my intuition is right. In that case, there's no constraint to set since infinitely many constraints exist.

      Comment


      • #4
        Well, if you fit the regression, you will get estimates for the coefficients of ln(x2) and ln(x3). As you note, they sum to -gamma. So -lincom- will get you an estimate of gamma, and then from there you can use either of those two coefficients to also calculate an estimate of alpha using -nlcom-. So the model does separately identify alpha and gamma, and you don't need to specify any constraints at all for that to work.

        By the way, you are right, that the sum is -gamma, not 1-gamma. I overlooked the -1 in the coefficient of ln(x2)
        Last edited by Clyde Schechter; 23 Jan 2016, 17:33.

        Comment


        • #5
          Apologies, but could you elaborate on the specific way lincom would be used? I've used it in two papers before, but in this case it seems alpha would only be identified if gamma is known, or vice versa, I think...

          Remember, both alpha and gamma are unknown. Although I can get least squares estimates of coef(x2) and coef(x3), there isn't a straightforward function (sum, difference, or ratio) that can be used to set them equal to a constant.

          Comment


          • #6
            It's just a little algebra. Let's call the coefficients from the regression b1, b2, and b3 for log x1 log x2 and log x3 respectively. The coefficient b1 has no real role here.

            But as you noted earlier b2 + b3 = - gamma, so you can estimate gamma as -b2 - b3.

            And since b3 = (1-alpha)*(1-gamma), we have 1 - alpha = b3/(1-gamma). So alpha = 1 - b3/(1-gamma) = (1-gamma - b3)/(1-gamma) = (1+ b2 + b3 - b3)/(1+b2+b3) = (1+b2)/(1+b2+b3)

            In Stata code, the notation is a bit clumsier, but:

            Code:
            gen logy = log(y)
            gen logx1 = log(x1)
            gen logx2 = log(x2)
            gen logx3 = log(x3)
            regress logy logx1 logx2 logx3, nocons // THE ORIGINAL EQUATION HAS NO CONSTANT TERM
            
            lincom -_b[logx2] - _b[logx3] // GIVES GAMMA
            nlcom (1+_b[logx3])/(1+_b[logx2]+_b[logx3]) // GIVES ALPHA

            Comment


            • #7
              Wow, very clever and thank you for taking the time to stick with it! Is there a particular process to follow when trying to manipulate variables to get some expression like the one you just got in terms of the coefficients on logx2 and logx3?

              Comment


              • #8
                No particular process. Just playing around with algebra and solving equations.

                By the way, I noticed there's a typo in my Stata command for computing alpha. It should read

                Code:
                nlcom (1+_b[logx2])/(1+_b[logx2]+_b[logx3]) // GIVES ALPHA

                Comment


                • #9
                  Perfect, the estimate I got now makes sense. Thanks again for catching that, and I'll be more clever with the algebraic manipulations in the future!

                  Comment

                  Working...
                  X