Announcement

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

  • getting the pvalue from t stat

    Hi everybody,

    I managed to store the coefficients, the standard errors and the t_stats of a particular regressor for a set of regressions and I would be interested to know the corresponding p_value. Do you know how to get them?
    I have tried with (2 * ttail(e(df_r), abs(_b[jobfather]/_se[jobfather]))) but it returns me missing values (.)

    Thanks

    Pietro

  • #2
    That works for me:

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . regress price mpg 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 |   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
    ------------------------------------------------------------------------------
    
    . di (2 * ttail(e(df_r), abs(_b[foreign]/_se[foreign])))
    .01383634
    So the error occurs somewhere else. One possible guess would be that the standard error is missing in your model. However, there are many other possible reasons, so without additional information there is little more we can say.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maybe the problem is that I'm trying to run it in a loop?

      foreach y of varlist `y'{
      fracglm `y' `controlVars1', vce(robust) link(p)
      post `myfile' (_b[jobfather]) (_se[jobfather]) (2 * ttail(e(df_r), abs(_b[jobfather]/_se[jobfather])))
      }

      it provides me correct coefficient and standard errors, it seems wired it does not work for p_values

      Comment


      • #4
        What is the command fracglm? Does that return e(df_r)? My suspicion is that that is not the case, a t-test is inappropriate for that model, and that you need to compare the Wald statistic with the standard normal distribution. See the last part of: http://www.stata-journal.com/article...article=st0137
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5

          Code:
          clear all
           input t y x1 x2
           1  89.1  96.7   101
           2  99.2  98.1 100.1
           3    99   100   100
           4   100 104.9  90.6
           5 111.6 104.9  86.5
           6 122.2 109.5  89.7
           7 117.6 110.8  90.6
           8 121.1 112.3  82.8
           9   136 109.3  70.1
          10 154.2 105.3  65.4
          11 153.6 101.7  61.3
          12 158.5  95.4  62.5
          13 140.6  96.4  63.6
          14 136.2  97.6  52.6
          15   168 102.4  59.7
          16 154.3 101.6  59.5
          17   149 103.8  61.3
           end
          
           tsset t
          qui reg y x1 x2 t
           matrix b=e(b)'
           matrix v=e(V)
           scalar df=e(df_r)
           mata: v= st_matrix("v")
           mata: se= sqrt(diagonal(v))
           mata: b= st_matrix("b")
           mata: t=  b:/se
           mata: df= st_numscalar("df")
           mata: p= 2*ttail(df,abs(t))
           mata: se= st_matrix("se",se)
           mata: t= st_matrix("t",t)
           mata: p= st_matrix("p",p)
           matrix stat = b , se , t , p
           matrix colnames stat = "B"  "SE"  "T"  "P>|t|"
           matrix rownames stat = x1 x2 t _cons
           reg y x1 x2 t
           matlist stat

          HTML Code:
          .  reg y x1 x2 t
          
                Source |       SS       df       MS              Number of obs =      17
          -------------+------------------------------           F(  3,    13) =   27.44
                 Model |  8335.47821     3  2778.49274           Prob > F      =  0.0000
              Residual |   1316.4803    13  101.267715           R-squared     =  0.8636
          -------------+------------------------------           Adj R-squared =  0.8321
                 Total |  9651.95851    16  603.247407           Root MSE      =  10.063
          
          ------------------------------------------------------------------------------
                     y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                    x1 |   .4213162   .4933296     0.85   0.409    -.6444576     1.48709
                    x2 |  -.9885772   .4572538    -2.16   0.050    -1.976414   -.0007405
                     t |   1.322487   1.509992     0.88   0.397    -1.939652    4.584627
                 _cons |   150.1613   60.72759     2.47   0.028     18.96734    281.3553
          ------------------------------------------------------------------------------
          
          . matlist stat
          
                       |         B         SE          T      P>|t|
          -------------+--------------------------------------------
                    x1 |  .4213162   .4933296   .8540258   .4085527
                    x2 | -.9885772   .4572538  -2.161988   .0498522
                     t |  1.322487   1.509992   .8758242   .3970202
                 _cons |  150.1613   60.72759   2.472703   .0279919
          Emad A. Shehata
          Professor (PhD Economics)
          Agricultural Research Center - Agricultural Economics Research Institute - Egypt
          Email: [email protected]
          IDEAS: http://ideas.repec.org/f/psh494.html
          EconPapers: http://econpapers.repec.org/RAS/psh494.htm
          Google Scholar: http://scholar.google.com/citations?...r=cOXvc94AAAAJ

          Comment


          • #6
            Notes:
            The above example valid when
            scalar df=e(df_r)
            Elsewhere choose a valid expression or number
            Last edited by Emad Shehata; 10 May 2016, 03:28.
            Emad A. Shehata
            Professor (PhD Economics)
            Agricultural Research Center - Agricultural Economics Research Institute - Egypt
            Email: [email protected]
            IDEAS: http://ideas.repec.org/f/psh494.html
            EconPapers: http://econpapers.repec.org/RAS/psh494.htm
            Google Scholar: http://scholar.google.com/citations?...r=cOXvc94AAAAJ

            Comment


            • #7
              Originally posted by Emad Shehata View Post
              The above example valid when
              scalar df=e(df_r)
              Elsewhere choose a valid expression or numbe
              If e(df_r) is not defined by your estimation command, then you should not choose a number. The t-distribution is nice, but only works in specific models. The most common example is linear regression. It is convention in Stata to return e(df_r) when the t-distribution is appropriate, otherwise leave it empty. So if e(df_r) is empty, then that is a clear sign, that the t-distribution is inappropriate. An example of a large set of models where this is the case is any model estimated using maximum (quasi-)likelihood, where you will need to compare the Wald statistic with the standard normal distribution rather than a t-distribution.
              ---------------------------------
              Maarten L. Buis
              University of Konstanz
              Department of history and sociology
              box 40
              78457 Konstanz
              Germany
              http://www.maartenbuis.nl
              ---------------------------------

              Comment


              • #8
                I mean about the number is degrees of freedom
                Not any number
                And some models not all df scalar are the same formula =e(df_r)
                Emad A. Shehata
                Professor (PhD Economics)
                Agricultural Research Center - Agricultural Economics Research Institute - Egypt
                Email: [email protected]
                IDEAS: http://ideas.repec.org/f/psh494.html
                EconPapers: http://econpapers.repec.org/RAS/psh494.htm
                Google Scholar: http://scholar.google.com/citations?...r=cOXvc94AAAAJ

                Comment


                • #9
                  fracglm is a user-written routine (by me) that is very similar to Stata 14's fracreg (but it only requires Stata 11.2). Like fracrec it returns z values, not t-values. The correct formula should be something like

                  Code:
                  . display 2 * (1 - normal(1.96))
                  .04999579
                  Note too that, after many/most estimation commands, if you do

                  Code:
                  mat list r(table)
                  you get a lot of information, including the p values. This information could be extracted via matrix commands if a user wanted to.

                  I've never officially released fracglm, partly because fracreg came along and greatly reduced the need for it. But it is useful for users condemned to using older versions of Stata. Also, at least for the moment, there is a bug in fracreg that causes it to report incorrect degrees of freedom but that is supposed to be fixed soon. If anyone wants fracglm more information is available at

                  http://www3.nd.edu/~rwilliam/xsoc739...onseModels.pdf
                  -------------------------------------------
                  Richard Williams, Notre Dame Dept of Sociology
                  StataNow Version: 19.5 MP (2 processor)

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

                  Comment

                  Working...
                  X