Announcement

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

  • t-stat and p-values


    Dear all, I have estimated several regressions using loop. I have managed to save the estimated alphas as new variables. Now I need to obtain the t-stats and p-values for each of these coefficients. Is there any way in Stata to save t-statistics and p-values of each regression in columns as new variables? Best regards

  • #2
    r(table) is one easy way to go. See http://www.statalist.org/forums/foru...s-as-variables or http://www.statalist.org/forums/foru...-using-ereturn
    -------------------------------------------
    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
      As I answered before ( http://www.talkstats.com/showthread....iable-in-STATA. ), no loops are necessary:

      Code:
      sysuse auto, clear
      statsby alpha=_b[_cons] se=_se[_cons] df=e(df_r) ,  by(rep78) noi : ///
              reg price mpg
              
      gen t = alpha/se
      gen p = 2*ttail(df,abs(t))
      
      list
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Thank you Richard Williams and Maarten Buis!
        Best regards!

        Comment


        • #5
          I conducted similar regression like Aiko and found this topic. I know it's pretty old, but still I post my solution here for some one may need it:

          g cons = . // blank variable for constant
          g se = . // blank variable for se
          g df = . // blank variable for df
          g t = . // blank variable for tt
          g p = . blank variable for p

          forvalue i=1/217{
          prais ri_rf mkt_rf smb hml umd if id==`i', robust // repeat regression according to id value, I have 217 value ID in this sample. I used prais for Carhart 4 factor model

          replace cons = _b[_cons] if _n == `i' // write value of constant of each regression to blank variable
          replace se = _se[_cons] if _n == `i' // write value of se of each regression to blank variable
          replace df = e(df_r) if _n == `i' // // write value of df of each regression to blank variable
          replace t = cons/se // calculate value of t of each regression to blank variable
          replace p = 2*ttail(df,abs(t)) // calculate value of p of each regression to blank variable
          }

          Hope this will help.

          Comment


          • #6
            Steve Nam:

            I can't see any advantage of this approach over statsby.

            Note that if _n == `i' is much slower than in `i' and that your two lines

            Code:
             
            replace t = cons/se 
            replace p = 2*ttail(df,abs(t))
            should be moved outside the loop


            Comment


            • #7
              Nick Cox:

              Thanks for your comment. I'm new to Stata, and above code is the only way I get it run as I expected.

              Should I change my code as below:

              statsby _b[_cons] _se[_cons] e(df_r), by (id): prais ri_rf mkt_rf smb hml umd, robust

              gen t = _b[_cons] /_se[_cons]
              gen p = 2*ttail(df,abs(t))

              list


              I tried this, but:

              1. Stata listed all regression result for all observations, which is not what I want. I have 217 unique ID, and it should return only 217 regressions
              2. Stata did not generate any t & p as in my previous code

              I guess I must be wrong else where. If you can point it out, I'll be very much appreciate.
              Last edited by Steve Nam; 04 Apr 2015, 03:57.

              Comment


              • #8
                1.Naturally I can't see your dataset to check anything. There should be one result for each distinct (not unique) value of the by() variable.

                2. You didn't follow my advice. Your statements were fine, but in the wrong place. What you will at best remember the last regression and at worst remember nothing.

                An example for understanding.

                Code:
                . sysuse auto, clear
                (1978 Automobile Data)
                
                . statsby se=_se[weight] slope=_b[weight], by(foreign) : regress mpg weight
                (running regress on estimation sample)
                
                      command:  regress mpg weight
                           se:  _se[weight]
                        slope:  _b[weight]
                           by:  foreign
                
                Statsby groups
                ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
                ..
                
                . l
                
                     +---------------------------------+
                     |  foreign         se       slope |
                     |---------------------------------|
                  1. | Domestic   .0004654   -.0059751 |
                  2. |  Foreign   .0024942    -.010426 |
                     +---------------------------------+
                
                . gen t = slope/se
                
                . l
                
                     +---------------------------------------------+
                     |  foreign         se       slope           t |
                     |---------------------------------------------|
                  1. | Domestic   .0004654   -.0059751   -12.83925 |
                  2. |  Foreign   .0024942    -.010426   -4.180132 |
                     +---------------------------------------------+

                Comment


                • #9
                  Hi Nick Cox,

                  I get it run. All I need is to save the file to new file to avoid "no; data in memory would be lost r(4);" error.

                  The rest can be done by following your example.

                  Thanks a lot.

                  P.S: I found the article about statsby by you, and it's really useful to me.

                  Comment


                  • #10
                    How can I obtain the robust standard errors when e.g. using . statsby seone=_se(variableone) : reg c_ ABLQ lag, rob it shows the value of 0 for all observations. Is there a command like _rse[variablename] to get the robust standard errors???

                    Comment

                    Working...
                    X