Announcement

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

  • Accessing confidence intervals after nlcom

    Dear Statalisters,

    I am trying to access confidence intervals from nlcom to be able to make a graph, however I cannot figure out how to do that. nlcom stores the transformed coefficients and the estimated variance-covariance matrix in r(), but not the confidence intervals. Is there any way to access them or to calculate them? esttab (from the Stata Journal) is able to do it but I don't know how. I know I can also use margins but I'm using nlcom because it allows to estimate multiple expressions at the same time.
    Code:
    . webuse grunfeld, clear
    
    . qui xtreg invest L(0/2).mvalue, fe
    
    . nlcom (_b[mvalue]) ///
    >           (_b[mvalue] + _b[L.mvalue]) ///
    >           (_b[mvalue] + _b[L.mvalue] + _b[L2.mvalue]), post
    
           _nl_1:  _b[mvalue]
           _nl_2:  _b[mvalue] + _b[L.mvalue]
           _nl_3:  _b[mvalue] + _b[L.mvalue] + _b[L2.mvalue]
    
    ------------------------------------------------------------------------------
          invest |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _nl_1 |   .1713403   .0205473     8.34   0.000     .1310683    .2116123
           _nl_2 |    .242995   .0236924    10.26   0.000     .1965588    .2894312
           _nl_3 |   .2848838   .0311509     9.15   0.000     .2238292    .3459384
    ------------------------------------------------------------------------------
    
    . esttab, ci
    
    --------------------------------------
                                    (1)   
                                 invest   
    --------------------------------------
    _nl_1                         0.171***
                          [0.131,0.212]   
    
    _nl_2                         0.243***
                          [0.197,0.289]   
    
    _nl_3                         0.285***
                          [0.224,0.346]   
    --------------------------------------
    N                               180   
    --------------------------------------
    95% confidence intervals in brackets
    * p<0.05, ** p<0.01, *** p<0.001

  • #2
    I don't think Stata leaves those behind anywhere. You can calculate them from the usual normal-theory formulas using the values in _b and _se.

    Comment


    • #3
      If your question is on how to calculate these intervals, then you just need to know the coefficient and standard error, nothing more. From your example:

      Code:
      webuse grunfeld, clear
      qui xtreg invest L(0/2).mvalue, fe
      nlcom (_b[mvalue]) ///
                 (_b[mvalue] + _b[L.mvalue]) ///
                 (_b[mvalue] + _b[L.mvalue] + _b[L2.mvalue]), post
      
      gen ll=.
      gen ul=.
      mat R1= r(b)'
      mat R2=r(V)
      local n= `= rowsof(R1)'
      forval i=1/`n'{
      replace ll= R1[`i',1]- (invnormal(.975)*(sqrt(R2[`i', `i']))) in `i'
      replace ul= R1[`i',1]+ (invnormal(.975)*(sqrt(R2[`i', `i']))) in `i'
      }
      preserve
      keep in 1/`n'
      mkmat ll ul, mat(C)
      restore
      mat l C
      To be honest, I would not bother programming this. Just pick up these confidence intervals by quietly calling esttab.

      Res.:

      Code:
      . mat l C
      
      C[3,2]
                 ll         ul
      r1  .13106829  .21161231
      r2  .19655876  .28943121
      r3  .22382917  .34593838

      Comment


      • #4
        Thank you Clyde and Andrew, this code is really helpful.

        I didn't realize that esttab stores the coefficients and confidence intervals in r(), so indeed that seems to be the simplest way to get them.

        Comment


        • #5
          I came across this after trying to extract a CI after doing a specific prediction. Fortunately, Stata does leave them behind in the r(table) matrix. E.g., if I wanted to know the expected value (and the CI around it) for an automobile that is 2000 pounds and 150 inches long, I might use this:

          sysuse auto, clear
          reg price weight length
          nlcom _b[_cons]+2000*_b[weight]+150*_b[length]
          mat list r(table)
          local evalu=round(r(table)[1,1], .01)
          local ll=round(r(table)[5,1], .01)
          local ul=round(r(table)[6,1], .01)
          di "The expected value of a vehicle that is 150 inches and 2000 pounds is {it:$`evalu'} with a 95% confidence interval between {it:$`ll'} and {it:$`ul'}"

          Comment

          Working...
          X