Announcement

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

  • How to draw a residual plot after xtreg, re command

    Dear Statalist,

    I am running a random effects model and would love to draw a residual plot of predicted vs. fitted values for my analysis.

    streng c.age##c.age##i.LTCsystem, re vce(cluster mergeid_n)
    rvfplot, yline(0)
    rvfplot2

    Nevertheless, the rvfplot command and rvfplot2 are not working. For rvfplot I receive the error: last estimates not found r(301) and for the rvfplot2 I receive the error: option residuals not allowed
    r(198).

    I have already looked into other with the same problem, but then rvfplot2 came up as a solution, which is not working with me.

    Thank you!

  • #2
    Sophie:
    do you mean something along the following lines?
    Code:
    . use "https://www.stata-press.com/data/r16/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtreg ln_wage age i.race
    
    Random-effects GLS regression                   Number of obs     =     28,510
    Group variable: idcode                          Number of groups  =      4,710
    
    R-sq:                                           Obs per group:
         within  = 0.1026                                         min =          1
         between = 0.1032                                         avg =        6.1
         overall = 0.0945                                         max =         15
    
                                                    Wald chi2(3)      =    3242.34
    corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
         ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |    .018534    .000331    55.99   0.000     .0178852    .0191828
                 |
            race |
          black  |  -.1209428   .0129079    -9.37   0.000    -.1462418   -.0956439
          other  |   .0981941   .0538424     1.82   0.068    -.0073351    .2037233
                 |
           _cons |    1.15423   .0118069    97.76   0.000     1.131089    1.177371
    -------------+----------------------------------------------------------------
         sigma_u |  .36581626
         sigma_e |  .30349389
             rho |  .59231394   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    
    . predict Fitted, xb
    (24 missing values generated)
    
    . predict Epsilon, e
    (24 missing values generated)
    
    . twoway (scatter Epsilon Fitted), ytitle(Epsilon residuals) xtitle(Fitted values)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Yes, thank you very much for the help!

      Comment

      Working...
      X