Announcement

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

  • xtqreg - fitted values and residuals

    Dear Statalists,

    I’m applying xtqreg on a panel of dimension i = 24 and t = 731 using bootstrapping for the standard errors and I would like to get the residuals.
    Unfortunately predict […], residuals give the infamous error : "option residuals not allowed, r(198)" even after updating the package.
    When I run the built-in option: “predict(yhat)” I get the following error message:
    Code:
    bootstrap, cluster(hour) rep(20) seed(123): xtqreg price solar wind load cable lag_price holiday mon tue thu fri sat sun jan feb mar may jun jul aug sep oct nov dec, quantile(0.5) predict(yhat)
     
    ------ Error ------
    Bootstrap replications (20): xxxxxxxxxxxxxxxxxxxx done
    x: Error occurred when bootstrap executed xtqreg.
    insufficient observations to compute bootstrap standard errors; no results will be saved
    r(2000);
    The same happen with greater replications.

    To get fitted values, I then tried to use “predict yhat” and ran smoothly (as in (2) in the code below). In addition, I also tried avoiding bootstrapping and use the built-in option of xtqreg (as in (1)). Comparing the two approaches, I get of course identical coefficients, different standard errors, yet completely different fitted values for the same quantile.

    Can someone help me understand why? Looking at the residuals (below), I personally have more confidence in the built-in option. Is it because the built-in option ignores statistically insignificant point estimates?
    Thanks a lot for your help and have a good one!
    Code:
    * no bootstrap (1)
    xtqreg price solar wind load cable lag_price holiday mon tue thu fri sat sun jan feb mar may jun jul aug sep oct nov dec, ls q(0.5) predict(yhat)
    gen res__5 = yhat__5 – price
     
    * bootstrap (2)
    foreach q in 1 2 3 4 5 6 7 8 9 {
                  bootstrap, cluster(hour) rep(20) seed(123): xtqreg price solar wind load cable lag_price holiday mon tue thu fri sat sun jan feb mar may jun jul aug sep oct nov dec, quantile(0.`q')
                 
                  *save results
                  eststo q_`q'
    }
     
    est restore q_5
    predict yhat_q5
    gen res_q5 = yhat_q5 - price
    Code:
    Fitted values and residuals from (1) and (2)
    Bootstrap (2)                               Buil-in (1)
    yhat_q5              res_q5              yhat__5                 res__5
    82.72142           81.34142           2.114745              .7347449
    86.12959           86.0396             4.127318              4.037318
    90.62315           90.54315           8.959707              8.879707
    94.21761           94.16761           14.13149              14.08149
    101.3495           101.2695           26.46717              26.38717
    107.6854           107.5954           40.13287              40.04287
    114.6512           114.1212           48.60219              48.07219
    122.9444           120.9144           54.53706              52.50706
    [...]

  • #2
    Maybe I am out of the loop here, but why do you want to create residuals at the same step where you estimate standard errors using bootstrapping? I would totally go with your
    Code:
    xtqreg price solar wind load cable lag_price holiday mon tue thu fri sat sun jan feb mar may jun jul aug sep oct nov dec, ls q(0.5) predict(yhat)
    gen res__5 = yhat__5 – price
    and then repeat for all quantiles of interest.
    Best wishes

    Stata 18.0 MP | ORCID | Google Scholar

    Comment


    • #3
      gen res_q5 = price - yhat_q5

      Comment


      • #4
        Looking over the code, the difference between predict(yhat) and predict after estimation is a unit fixed effect that consists of two parts (the unit fixed effect from xtreg plus another effect). Code is fairly easy to follow if you're interested (depending on what "residual" you're after).

        Comment


        • #5
          Felix Bittmann :
          Yes, you are completely right. I use bootstrap because my variables are not symmetric and some are heavily positively skewed. Using bootsrapping rather than clustered gives slightly different standard errors, yet enough to affect statistical significance of some binary variables. I therefore prefer to follow the literature and be more conservative in my analysis.
          At first, I tried the "predict" command after the loop, as in (2). Then I came across the "predict()" option of xtqreg and, when I compared the two fitted values, I've found that difference that made me doubt.
          I guess the simpler, the better. Thank you for your answer !

          George Ford :
          Thank you for spotting my blunder and for your answer !
          If I understand correctly, the difference between the two ways of computing fitted values comes from the fact that "predict" after the loop doesn't take into account fixed effect.
          In their work, Joao Santos Silva and co-author mention that there are (i) classical unit fixed effect (alpha_i) and (ii) quantile specific unit fixed effects (small delta _i). Is this what you mean in "a unit fixed effect that consists of two parts" ?
          I would like to get residuals to test their (and their power) independence from regressors (as suggested here #26). Since I get fitted values for each quantile, I've chosen those at the median, which overlaps with the mean in case of my dependent variable. And why not having a look at the code you mentioned.

          Thanks a lot !

          Comment


          • #6
            You have N = 24 and T = 731? This command was not meant for this scenario, and the panel bootstrap can’t be justified. You need to use large T asymptotics. You can include 24 dummies and use qreg. But standard errors are hard to get. If you are using OLS it would be Driscoll-Kraay.

            Comment


            • #7
              Dear Elia Scapini,

              I think that there are two separate issues here.

              1) As far as I can see, the problem you are having simply results from the fact that you are doing the bootstrap in a loop where the last quantile estimated is 0.9. Therefore, when you predict after that, you get predictions for that quantile, and not for the median as you are doing without bootstrap. This is the easy part.

              2) The difficult part is that, as Jeff noted above, I do not think your bootstrap will help you when you have N = 24 and T = 731. Unfortunately I do not know of a good way to get reliable standard errors in this case (i.e., the QR equivalent of Driscoll-Kraay s.e.).

              Best wishes,

              Joao

              Comment


              • #8
                Dear All,

                Correct, I have n = 24 and T = 731.
                I understand, I will see what I can do with xtscc.

                Many thanks for your precious contribution and your time.

                Elia

                Comment

                Working...
                X