Announcement

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

  • Unable to replicate Stata 16 code local x = r(table)[1,1] in Stata 15

    Dear all,

    I have run into a problem trying to replicate some code from Stata 16 in Stata 15. Do you have any idea of what might be going on? I read the update notes and could not identify why this is happening.

    Here you have the code that works in Stata 16.

    Code:
    . * Using Stata SE 16.1
    .
    . sysuse auto.dta, clear
    (1978 Automobile Data)
    
    .
    . recode rep78 (2=1) (3/5=0)
    (rep78: 67 changes made)
    
    .
    . probit rep78 mpg headroom
    
    Iteration 0:   log likelihood = -28.552789  
    Iteration 1:   log likelihood = -27.844339  
    Iteration 2:   log likelihood = -27.837343  
    Iteration 3:   log likelihood = -27.837342  
    
    Probit regression                               Number of obs     =         69
                                                    LR chi2(2)        =       1.43
                                                    Prob > chi2       =     0.4890
    Log likelihood = -27.837342                     Pseudo R2         =     0.0251
    
    ------------------------------------------------------------------------------
           rep78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -.0482431    .043335    -1.11   0.266    -.1331782     .036692
        headroom |  -.0784669   .2285802    -0.34   0.731    -.5264758     .369542
           _cons |    .168579   1.340746     0.13   0.900    -2.459235    2.796393
    ------------------------------------------------------------------------------
    
    .
    . local c2_apath_coef = round(r(table)[1,1], .01)
    
    .
    . di `c2_apath_coef'
    -.05
    
    .
    end of do-file
    Here the same code that generates an error in Stata 15

    Code:
    . * Using Stata SE 15.1
    .  
    . sysuse auto.dta, clear
    (1978 Automobile Data)
    
    . 
    . recode rep78 (2=1) (3/5=0)
    (rep78: 67 changes made)
    
    . 
    . probit rep78 mpg headroom
    
    Iteration 0:   log likelihood = -28.552789  
    Iteration 1:   log likelihood = -27.844339  
    Iteration 2:   log likelihood = -27.837343  
    Iteration 3:   log likelihood = -27.837342  
    
    Probit regression                               Number of obs     =         69
                                                    LR chi2(2)        =       1.43
                                                    Prob > chi2       =     0.4890
    Log likelihood = -27.837342                     Pseudo R2         =     0.0251
    
    ------------------------------------------------------------------------------
           rep78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -.0482431    .043335    -1.11   0.266    -.1331782     .036692
        headroom |  -.0784669   .2285802    -0.34   0.731    -.5264758     .369542
           _cons |    .168579   1.340746     0.13   0.900    -2.459235    2.796393
    ------------------------------------------------------------------------------
    
    .  
    . local c2_apath_coef = round(r(table)[1,1], .01)
    invalid syntax
    r(198);
    
    end of do-file
    Last edited by Enrique Hernandez; 26 May 2020, 02:27.

  • #2
    Did you see the mistake yet?

    If not, then compare the two lines here
    Code:
    local c2_apath_coef = round(r(table)[1,1], .01)
    local c2_apath_coef = r(table)[1,1], .01)

    Comment


    • #3
      Dear Joseph,

      Thanks for your reply and for noticing the mistake and divergence between the two codes. I have corrected the mistake in the original post, but the problem persists.

      Do you have any idea of what might be going on?

      Comment


      • #4
        My recollection is that the ability to refer to explicitly-subscripted stored results, as in
        Code:
         
         r(table)[1,1]
        was a feature introduced in Stata 16.

        In both Stata 15 and 16 you could (warning -- untested):

        Code:
        matrix T = r(table)
        local c2_apath_coef = round(T[1,1], .01)

        Comment


        • #5
          I don't have access to Stata 15 at present, but in general


          Code:
          local foo = round(whatever, 0.1)
          is almost(*) never better than

          Code:
          local foo : di %2.1f whatever
          as the first sometimes bites you and the second never should.

          Rounding to multiples of 0.1, 0.01, 0.001, ... is a formatting question, not a matter of decimal arithmetic, as most multiples of 0.1, 0.01, 0.001, ... cannot be held in exact binary equivalents.

          (*) I can't think of an exception right now, hence the mild fence-sitting.

          (This doesn't solve the question posed.)

          Comment


          • #6
            Thanks Stephen, your solution works perfectly.

            I am happy that new feature was introduced in Stata 16.

            Thanks Nick for your useful advice on rounding.

            Comment


            • #7
              Also, see function el() as in

              Code:
              local c2_apath_coef = round(el(r(table), 1, 1), .01)
              Best
              Daniel

              Comment


              • #8
                Stephen Jenkins is right.




                8. Matrix subscripting and extraction are now allowed with r() and e() matrices, including e(b), e(V), and e(Cns). For example,

                . sysuse auto
                . regress mpg turn trunk
                . display e(v)["turn","trunk"]



                This information can be found at https://www.stata.com/help.cgi?whatsnew15to16 -- regardless of whether Stata 16 is installed.

                Comment

                Working...
                X