Announcement

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

  • Variance of each single residual

    Hi Statlist,

    I am struggling into constructing the residuals' specific variance for the following model:

    Code:
    xtreg tasso_crescita_sales_prod L.log_sales L.dummy_2 L2.dummy_2 L3.dummy_2 mean_gr_rate_atc2 recalls_sales ageprodcat1 ageprodcat2 ageprodcat3 ageprodcat4 newmolfirm newmolmarket i.Year, fe vce(cluster idpr)
    What I would like to do is to generate a variable consisting of the variance of regression residuals so that each residual has its own variance (not gen var = e(sigma_e) which generates a unique value). So, if we call the residuals AVit (resulting from AVit = y - yhat where yhat = predict yhat, xbu) , I would like to obtain Var(AVit ). Afterwords my aim is to compute the average over Nt , where Nt is the number of units with available data in t of such variances. Something like:

    Sum for i ranging from 1 to Nt of Var(AVit ) over (Nt )2​​​​​​​


    Is it possible in STATA to do compute the variance of such residuals?
    Last edited by Federico Nutarelli; 30 Oct 2019, 03:43.

  • #2
    Federico:
    do you mean something along the following lines?
    Code:
    use "http://www.stata-press.com/data/r15/nlswork.dta"
    xtreg ln_wage age
    predict e, e
    quetly sum e
    g var_e=(e-r(mean))^2/(r(N)-1)
    list e var_e in 1/10
    . list e var_e in 1/10
    
         +----------------------+
         |         e      var_e |
         |----------------------|
      1. | -.4115784   5.94e-06 |
      2. | -.8527393   .0000255 |
      3. | -.3099484   3.37e-06 |
      4. | -.1382197   6.70e-07 |
      5. | -.1786144   1.12e-06 |
         |----------------------|
      6. | -.2140789   1.61e-06 |
      7. |  .4826497   8.17e-06 |
      8. |  .5032557   8.88e-06 |
      9. |  .3161016   3.50e-06 |
     10. |  .4728792   7.84e-06 |
         +----------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Thank you very much for the reply Carlo,

      Ok then. I see that the only way is to construct it by hand. The question was also meant to open a quick discussion about residuals of fixed effects. If I had to construct confidence intervals, is it safer to take the prediction given by predict, e or the predictions given by predict, ue? As far as I have understood from the help, if I do something like:

      Code:
      predict yhat, xbu
      gen av_t = tasso_crescita_sales - yhat
      I am taking "e" since I am ruling out the individual heterogeneity. But am still quite undecided on which one are the "proper residuals" to construct confidence intervals.

      Furthermore, I have individuals constituted by products and Years. when doing r(N) I am taking the bulk of all individuals in all years. Is it correct or something like by(Year) or by(individual) should be done?


      Thank you again!
      Last edited by Federico Nutarelli; 30 Oct 2019, 04:00.

      Comment


      • #4
        Better, to quote "Econometric Analysis of Cross Section and Panel Datahttps://jrvargas.files.wordpress.com › 2011/01 › wooldridge_j-_2002_eco..." (pag. 271-272) what I would like to obtain are the (u_hat_it)^2 and not the (sigma_u)

        Comment

        Working...
        X