Announcement

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

  • How to get confidence intervals for fitted in xtmixed post-estimation?

    Do anyone know how I can obtain confidence intervals when I run post-estimation after xtmixed? If I run e.g.

    . predict yhat_school, fitted level(school)

    I could get the expected values but I also would like the confidence intervals for the Point Estimates or the confidence bounderies.

  • #2
    I believe you would need to do the following:

    Code:
    predict se_xb, stdp
    predict u, reffects reses(se_u) relevel(school)
    gen se = sqrt(se_xb^2 + se_u^2)
    The first line gets you the standard error of the fixed-effects predictor. The second line gets you the random effects at the school level as well as their standard deviations. Finally, since the model assumes that the fixed and random effects are orthogonal, the overall standard error for the fitted (xb + u) value is the square root of the sum of those squared.

    By the way, if you are using the current version of Stata, the command is now called -mixed-, not -xtmixed-, although the latter name is still recognized as a synonym.

    Comment


    • #3
      Dear Clyde,

      may I ask you whether the formula for the standard errors of this prediction would change if we allow the cov(unstructured)? Do we need to take into account the covariances into account while computing the standard errors of the prediction? I have a similar problem to Max, although not identical since I want to predict at the lowest level and I have a random slope model which allows a correlation between the random slopes and intecepts. I posted more details about it here http://www.statalist.org/forums/foru...v-unstructured if you would like to see it.

      Thanks!

      Anna

      Comment


      • #4
        Yes it would change. In general, if you are calculating the variance of a sum of random variables x1, ..., xn which have covariance matrix V, then that will be given by (1, 1, ..., 1)*V*(1, 1, ..., 1)' , where ' denotes transpose. So if xb and u were not independent in #2 and had some covariance c, then the variance of the sum would be se_xb^2 + 2c + se_u^2. Your situation is more complicated because you have several terms, so there are several cross-terms to consider, derived from the estimated covariance matrix for the random effects. If you had three things, x1, x2, x3 then the variance is Var(x1) + 2*Cov(x1, x2) + 2*Cov(x2, x3) + 2*Cov(x1, x3) + Var(x2) + Var(x3).

        Coding this in any generality gets complicated. If you have only a single or small number of applications, you are probably best off doing the matrix algebra by hand and then just coding the appropriate quadratic form in your -gen se...- statement.

        Comment


        • #5
          Thank you, Clyde! It indeed looks complicated. Could you let me know where I take the covariances from? I obtained the BLUP standard errors from predict name, reses but what about the covariances? I found a formula in one of the old posts which would suggest me to do the following:

          matrix list e(b)
          scalar cov1=(exp(2*[atr1_1_1_2]_cons)-1)/(exp([atr1_1_1_2]_cons)+1)*exp([lns1_1_1]_cons)*exp([lns1_1_2]_cons)
          scalar cov2=(exp(2*[atr2_1_1_2]_cons)-1)/(exp([atr2_1_1_2]_cons)+1)*exp([lns2_1_1]_cons)*exp([lns2_1_2]_cons)

          and then:

          g se_y_hat=sqrt(se_fixed^2+(se_random1*year_spline)^ 2+se_random2^2+(se_random3*year_spline)^2+se_rando m4^2+sd_res^2+2*cov1+2*cov2)

          But I am not sure whether in this way I get the right covariances?

          I am attaching my Stata output for your better understanding (the name of the variables are a bit different than in my post, because I tried to simplify them, but otherwise it should all look straightforward)
          Attached Files

          Comment


          • #6
            Well, you can do it that way. But I always have trouble figuring out which of these atr_?_?_? values are which. Easier is, after -mixed- to run -estat recovariance-. This will list the covariance matrices and, most important, returns copies of them in r(). I believe the matrices are called r(Cov2), r(Cov3) etc. for the different levels. But, don't rely on my memory for that at this point. Just run -return list- and you'll see what they're called. Remember that those are "virtual" matrices, and to work with them effectively you will need to copy them to real matrices (-matrix C2 = r(Cov2)-, etc.).

            Comment


            • #7
              Dear Clyde and Max, Could you tell me how to get effect sizes for fitted in xtmixed or mixed post-estimation? Thanks.

              Comment


              • #8
                Thanks a lot, Clyde, that was very helpful!

                Comment

                Working...
                X