Announcement

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

  • Error when trying to extract the P-value from a rolling OLS regression

    Hi. I have been using command 'rolling' to estimate a rolling OLS regression of Y on X1. I have been trying to store the rolling constant estimates together with the underlying p-values. Specifically, I am running the following command:

    rolling alfa=_b["_cons"] pval=r(table)["pvalue" ,"_cons"], window(20): regress Y X1

    I am getting the following error message.

    type mismatch
    error in expression: r(table)
    r(109);


    Could anyone bring some light? Thank you.

  • #2
    What release of Stata are you using?

    Comment


    • #3
      I'm just guessing here, but it looks like your trying to store the entire table matrix into the pval stat...... maybe the solution would be to do the equivalent of
      Code:
      Pvalue=_p["var"]
      by the way, I've no experience with this specific prefix, I was just guessing

      Comment


      • #4
        Thank you both.
        William Lisowski, I am working on StataMP 16.1.
        Jared Greathouse, the allowed underscore variables are only _b and _se. I tried using _p in any case, but didn't work.

        Comment


        • #5
          This is a little subtle. If you look at the output of help rolling and click on exp_list in the command syntax, you will see the output of help exp_list which requires careful reading to figure out that if you are not using _b or _se but rather a standard Stata expression like r(table)["pvalue" ,"_cons"] you will need to enclose that expression in parentheses. So your command should work if you add parentheses as in
          Code:
          rolling alfa=_b["_cons"] pval=(r(table)["pvalue" ,"_cons"]), window(20): regress Y X1
          My apologies for sending you down a dead end by asking about your version; I was away from my computer and was unable to confirm that the problem is not version-related until now.

          Comment


          • #6
            it looks like your trying to store the entire table matrix into the pval stat
            No, that is standard syntax for subscripting matrices using row and column names.
            Code:
            . sysuse auto, clear
            (1978 automobile data)
            
            . regress price weight
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(1, 72)        =     29.42
                   Model |   184233937         1   184233937   Prob > F        =    0.0000
                Residual |   450831459        72  6261548.04   R-squared       =    0.2901
            -------------+----------------------------------   Adj R-squared   =    0.2802
                   Total |   635065396        73  8699525.97   Root MSE        =    2502.3
            
            ------------------------------------------------------------------------------
                   price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                  weight |   2.044063   .3768341     5.42   0.000     1.292857    2.795268
                   _cons |  -6.707353    1174.43    -0.01   0.995     -2347.89    2334.475
            ------------------------------------------------------------------------------
            
            . matrix list r(table)
            
            r(table)[9,2]
                        weight       _cons
                 b   2.0440626  -6.7073534
                se   .37683413   1174.4296
                 t   5.4243032  -.00571116
            pvalue   7.416e-07   .99545897
                ll   1.2928575    -2347.89
                ul   2.7952677   2334.4753
                df          72          72
              crit   1.9934636   1.9934636
             eform           0           0
            
            . // extract the pvalue for the constant
            . display %9.3f r(table)["pvalue","_cons"]
                0.995
            
            . // in earlier versions this syntax was needed
            . display %9.3f r(table)[rownumb(r(table),"pvalue"),colnumb(r(table),"_cons")]
                0.995
            
            .

            Comment


            • #7
              Originally posted by William Lisowski View Post
              This is a little subtle. If you look at the output of help rolling and click on exp_list in the command syntax, you will see the output of help exp_list which requires careful reading to figure out that if you are not using _b or _se but rather a standard Stata expression like r(table)["pvalue" ,"_cons"] you will need to enclose that expression in parentheses. So your command should work if you add parentheses as in
              Code:
              rolling alfa=_b["_cons"] pval=(r(table)["pvalue" ,"_cons"]), window(20): regress Y X1
              My apologies for sending you down a dead end by asking about your version; I was away from my computer and was unable to confirm that the problem is not version-related until now.

              Thank you very very much. This example should be added to the 'rolling' help file!

              Comment


              • #8
                Oh yes William Lisowski , you're right it is. I didn't recognize it as such at first since I usually subscript by number.

                Comment

                Working...
                X