Announcement

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

  • how to do calculations with the coefficients that i obtained

    after running OLS regression,

    I want to automatically do calculations with the coefficients I obtained.

    if for example I want to get a number by doing

    value = (b1 + b2)/1 - (a1 +a2)

    how can I code this?

    Thanks

  • #2
    Olivia,
    First, please detail what you mean by b1, b2, a1 and a2.
    Generally b stands for the coefficients, and I assume a stand for the value of the variable, but this is not obvious.

    If I'm right on a and b, you should use some locals from the matrix of coefficients here.
    Code:
     matrix b = e(b)
    local b1=b[1,1]
    local b2=b[1,2]
    gen newvar=(`b1'+`b2')/1-(a1+a2)
    Best,
    Charlie
    Last edited by Charlie Joyez; 24 Oct 2016, 13:42.

    Comment


    • #3
      you can use the expression builder (data-other utilities - hand calculator - create - coefficients).
      you can also see the names of the coefficients by using the coeflegend option:
      Code:
      . sysuse auto
      (1978 Automobile Data)
      
      . reg price mpg weight
      
            Source |       SS           df       MS      Number of obs   =        74
      -------------+----------------------------------   F(2, 71)        =     14.74
             Model |   186321280         2  93160639.9   Prob > F        =    0.0000
          Residual |   448744116        71  6320339.67   R-squared       =    0.2934
      -------------+----------------------------------   Adj R-squared   =    0.2735
             Total |   635065396        73  8699525.97   Root MSE        =      2514
      
      ------------------------------------------------------------------------------
             price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               mpg |  -49.51222   86.15604    -0.57   0.567    -221.3025     122.278
            weight |   1.746559   .6413538     2.72   0.008      .467736    3.025382
             _cons |   1946.069    3597.05     0.54   0.590    -5226.245    9118.382
      ------------------------------------------------------------------------------
      
      . reg price mpg weight, coeflegend
      
            Source |       SS           df       MS      Number of obs   =        74
      -------------+----------------------------------   F(2, 71)        =     14.74
             Model |   186321280         2  93160639.9   Prob > F        =    0.0000
          Residual |   448744116        71  6320339.67   R-squared       =    0.2934
      -------------+----------------------------------   Adj R-squared   =    0.2735
             Total |   635065396        73  8699525.97   Root MSE        =      2514
      
      ------------------------------------------------------------------------------
             price |      Coef.  Legend
      -------------+----------------------------------------------------------------
               mpg |  -49.51222  _b[mpg]
            weight |   1.746559  _b[weight]
             _cons |   1946.069  _b[_cons]
      ------------------------------------------------------------------------------
      
      . disp (_b[mpg]+_b[weight])/(1-_b[_cons])
      .02455731

      Comment


      • #4
        A better way to compute nonlinear combinations of coefficients is to use the nlcom postestimation command as it also provides corresponding standard errors.

        Based on Ariel's example:
        Code:
        . nlcom (_b[mpg]+_b[weight])/(1-_b[_cons])
        
               _nl_1:  (_b[mpg]+_b[weight])/(1-_b[_cons])
        
        ------------------------------------------------------------------------------
               price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
               _nl_1 |   .0245573   .0148019     1.66   0.097    -.0044539    .0535685
        ------------------------------------------------------------------------------
        https://www.kripfganz.de/stata/

        Comment

        Working...
        X