Announcement

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

  • Calculating p-values after oprobit using ereturn

    I am trying to calculate p-values for coefficients after an oprobit regression, using the directions in "Stata tip 53: Where did my p-values go?" (http://www.stata-journal.com/sjpdf.h...iclenum=st0137)

    Here is the example:
    . local t = _b[foreign]/_se[foreign]
    . di 2*ttail(e(df_r),abs(`t ́)) However, when I do ereturn list, there is no df_r, only df_m (results of ereturn list shown below). I'm not sure what the difference is, but when I try to use df_m to calculate the p-values, I do not get the correct values.
    Any advice on how to calculate the p-values would be much appreciated!
    Thanks,
    Susan


    . ereturn list

    scalars:
    e(rank) = 42
    e(N) = 220503
    e(ic) = 3
    e(k) = 42
    e(k_eq) = 11
    e(k_dv) = 1
    e(converged) = 1
    e(rc) = 0
    e(ll) = -401494.4658840121
    e(k_eq_model) = 1
    e(ll_0) = -414969.3276823036
    e(df_m) = 32
    e(chi2) = 26949.723596583
    e(p) = 0
    e(N_cd) = 0
    e(k_cat) = 11
    e(k_aux) = 10
    e(r2_p) = .0324719464774701

    macros:
    e(cmdline) : "oprobit ar_emp_LTR tenuremonths _Icycle_* _Izone_* _Ib.."
    e(cmd) : "oprobit"
    e(predict) : "oprobi_p"
    e(title) : "Ordered probit regression"
    e(chi2type) : "LR"
    e(opt) : "moptimize"
    e(vce) : "oim"
    e(user) : "mopt__oprobit_d2()"
    e(ml_method) : "d2"
    e(technique) : "nr"
    e(which) : "max"
    e(depvar) : "ar_emp_LTR"
    e(properties) : "b V"

    matrices:
    e(b) : 1 x 42
    e(V) : 42 x 42
    e(cat) : 1 x 11
    e(ilog) : 1 x 20
    e(gradient) : 1 x 42

    functions:
    e(sample)

  • #2
    You are using the formula for t when you should be using the formula for z. See section 4 of Maarten's paper. See if this works:

    Code:
    local z = _b[foreign]/_se[foreign]
    di 2*normal(-abs(`z'))
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Or you can also find the p-values directly in the matrix r(table) that -oprobit- returns. Depending on what you plan to do, extracting them from that matrix may be easier than calculating them from _b and _se, or not.

      Comment


      • #4
        I didn't know about r(table). I wonder why oprobit gets special treatment, e.g. you don't get r(table) after regress. Requests like Susan's are very common, so why not make r(table) a universal feature of estimation commands?
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          I think all the estimation commands now return r(table).

          Code:
           . sysuse auto
          (1978 Automobile Data)
            . regress price mpg i.foreign
                  Source |       SS       df       MS              Number of obs =      74
          -------------+------------------------------           F(  2,    71) =   14.07
                 Model |   180261702     2  90130850.8           Prob > F      =  0.0000
              Residual |   454803695    71  6405685.84           R-squared     =  0.2838
          -------------+------------------------------           Adj R-squared =  0.2637
                 Total |   635065396    73  8699525.97           Root MSE      =  2530.9
            ------------------------------------------------------------------------------
                 price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
                       |
               foreign |
              Foreign  |   1767.292    700.158     2.52   0.014     371.2169    3163.368
                 _cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
          ------------------------------------------------------------------------------
            . return list
            scalars:
                        r(level) =  95
            macros:
                       r(label2) : "(base)"
            matrices:
                        r(table) :  9 x 4
            . matrix list r(table)
            r(table)[9,4]
                                      0b.          1.           
                         mpg     foreign     foreign       _cons
               b  -294.19553           0   1767.2922   11905.415
              se   55.691719           .   700.15797   1158.6345
               t  -5.2825724           .   2.5241336   10.275385
          pvalue   1.333e-06           .   .01383634   1.085e-15
              ll  -405.24167           .    371.2169   9595.1638
              ul   -183.1494           .   3163.3676   14215.667
              df          71          71          71          71
            crit   1.9939434   1.9939434   1.9939434   1.9939434
           eform           0           0           0           0
          .

          Comment


          • #6
            I stand corrected. I was doing ereturn list, not return list, and I didn't see it after running regress. Anyway, nice enhancement. Searching through -help whatsnew-, I see that this was added in Stata 12. For more info see the bottom of -help ereturn- . Programmers should probably try to add this to their user-written estimation routines.

            EDIT: Or, maybe Stata just does this for programmers. My oglm program returns r(table), even though I never explicitly told it to do so.
            Last edited by Richard Williams; 09 Jul 2014, 11:50.
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              Thanks so much, this is great!
              If I want to use r(table), how do I access the p-value of a specific variable, e.g. the value for mpg in your example?

              Comment


              • #8
                P values are in the 4th row of the matrix. Getting the column numbers straight might get confusing because factor variables take up multiple columns, Try something like

                Code:
                . sysuse auto, clear
                (1978 Automobile Data)
                
                . regress price mpg i.foreign
                
                      Source |       SS       df       MS              Number of obs =      74
                -------------+------------------------------           F(  2,    71) =   14.07
                       Model |   180261702     2  90130850.8           Prob > F      =  0.0000
                    Residual |   454803695    71  6405685.84           R-squared     =  0.2838
                -------------+------------------------------           Adj R-squared =  0.2637
                       Total |   635065396    73  8699525.97           Root MSE      =  2530.9
                
                ------------------------------------------------------------------------------
                       price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                         mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
                             |
                     foreign |
                    Foreign  |   1767.292    700.158     2.52   0.014     371.2169    3163.368
                       _cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
                ------------------------------------------------------------------------------
                
                . mat list r(table)
                
                r(table)[9,4]
                                            0b.          1.            
                               mpg     foreign     foreign       _cons
                     b  -294.19553           0   1767.2922   11905.415
                    se   55.691719           .   700.15797   1158.6345
                     t  -5.2825724           .   2.5241336   10.275385
                pvalue   1.333e-06           .   .01383634   1.085e-15
                    ll  -405.24167           .    371.2169   9595.1638
                    ul   -183.1494           .   3163.3676   14215.667
                    df          71          71          71          71
                  crit   1.9939434   1.9939434   1.9939434   1.9939434
                 eform           0           0           0           0
                
                . mat mytable = r(table)
                
                . scalar pval = mytable[4,1]
                
                . di pval
                1.333e-06
                You probably have something more ambitiious in mind though. What would you ultimately like?
                -------------------------------------------
                Richard Williams, Notre Dame Dept of Sociology
                StataNow Version: 19.5 MP (2 processor)

                EMAIL: [email protected]
                WWW: https://www3.nd.edu/~rwilliam

                Comment


                • #9
                  one caveat; as I have previously said re: r(table), I recommend that one first make the matrix into one of your own; e.g., mat def junk=r(table); saved results can disappear and will unless you make them "permanent"

                  Comment


                  • #10
                    Maybe it is just me, but I have a hard time working with returned matrices unless I make a copy of them. I can never get the syntax right. Could I do the following working directly with r(table)?

                    Code:
                    mat mytable = r(table)
                    scalar pval = mytable[4,1]
                    -------------------------------------------
                    Richard Williams, Notre Dame Dept of Sociology
                    StataNow Version: 19.5 MP (2 processor)

                    EMAIL: [email protected]
                    WWW: https://www3.nd.edu/~rwilliam

                    Comment


                    • #11
                      The el() function works with all matrices except e(b), e(V), and e(Cns).

                      Here is Richard's example without making a copy of r(table).

                      Code:
                      . sysuse auto
                      (1978 Automobile Data)
                      
                      . regress price mpg i.foreign
                      
                            Source |       SS       df       MS              Number of obs =      74
                      -------------+------------------------------           F(  2,    71) =   14.07
                             Model |   180261702     2  90130850.8           Prob > F      =  0.0000
                          Residual |   454803695    71  6405685.84           R-squared     =  0.2838
                      -------------+------------------------------           Adj R-squared =  0.2637
                             Total |   635065396    73  8699525.97           Root MSE      =  2530.9
                      
                      ------------------------------------------------------------------------------
                             price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                      -------------+----------------------------------------------------------------
                               mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
                                   |
                           foreign |
                          Foreign  |   1767.292    700.158     2.52   0.014     371.2169    3163.368
                             _cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
                      ------------------------------------------------------------------------------
                      
                      . matrix list r(table)
                      
                      r(table)[9,4]
                                                  0b.          1.            
                                     mpg     foreign     foreign       _cons
                           b  -294.19553           0   1767.2922   11905.415
                          se   55.691719           .   700.15797   1158.6345
                           t  -5.2825724           .   2.5241336   10.275385
                      pvalue   1.333e-06           .   .01383634   1.085e-15
                          ll  -405.24167           .    371.2169   9595.1638
                          ul   -183.1494           .   3163.3676   14215.667
                          df          71          71          71          71
                        crit   1.9939434   1.9939434   1.9939434   1.9939434
                       eform           0           0           0           0
                      
                      . scalar pval = el(r(table),4,1)
                      
                      . di pval
                      1.333e-06

                      Comment


                      • #12
                        Thanks Jeff. I suspected it was something like that. I think it is still probably better to make a copy of the matrix, partly so you don't lose it, and partly because the syntax seems a bit simpler.
                        -------------------------------------------
                        Richard Williams, Notre Dame Dept of Sociology
                        StataNow Version: 19.5 MP (2 processor)

                        EMAIL: [email protected]
                        WWW: https://www3.nd.edu/~rwilliam

                        Comment


                        • #13
                          Thanks, Richard. The example you gave is great.
                          Thanks all for the help!

                          Comment


                          • #14
                            Sure. I like threads where I learn something (or in this case finally learn something, since Rich Goldstein pointed out r(table) in an earlier thread and I totally missed its usefulness.) You can either learn some matrix manipulation commands now; or extract the values one by one (instead of calculating them) and do whatever it is you were originally planning,
                            -------------------------------------------
                            Richard Williams, Notre Dame Dept of Sociology
                            StataNow Version: 19.5 MP (2 processor)

                            EMAIL: [email protected]
                            WWW: https://www3.nd.edu/~rwilliam

                            Comment


                            • #15
                              Originally posted by Richard Williams View Post
                              You are using the formula for t when you should be using the formula for z. See section 4 of Maarten's paper. See if this works:

                              Code:
                              local z = _b[foreign]/_se[foreign]
                              di 2*normal(-abs(`z'))
                              @Richard Williams Hi Richard, may I ask you a question about the p-values with respect to z statistics and t statistics ?

                              When reporting z statistics, p-value = 2*normal(-abs(z)) where z = _b[foreign]/_se[foreign]

                              However, when reporting t statistics, p-value becomes 2*ttail(e(df_r),abs(t)) where t = _b[foreign]/_se[foreign]

                              Thus, are these above correct? Many thanks in advance!!

                              Comment

                              Working...
                              X