Announcement

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

  • Stata MIXED Extract Intercept, Slope

    Code:
     
     mixed weight week || id: week predict u1 u0, reffects  generate intercept = _b[_cons] + u0  generate slope = _b[week] + u1

    If I wish for to estimate and store id-specific intercept and slope I can use the code above, but when I do it with week-squared (week2) I get errors...

    Code:
     
     mixed weight week week2 || id: week week2  predict u1 u0, reffects  generate intercept = _b[_cons] + u0  generate slope = _b[week] + u1
    Last edited by Leon Edelman; 19 Dec 2023, 13:46.

  • #2
    Your question is not clear.

    when I do it with week-squared (week2) I get errors...
    What errors? Use one of the datasets in

    Code:
    help mixed
    to illustrate exactly what you are doing and what the issue is.

    Comment


    • #3
      Andrew Musau What isn't clear? I specified the model and my issue. The error is that the predicted intercepts and slopes when I include week-squared doesn't make any sense.

      Comment


      • #4
        Clyde Schechter Do you have a response to predicting intercepts and slopes when you have a squared-time term?

        Comment


        • #5
          I think the issue might be that you have three random variances but you only ask for two predictions from the predict command.
          Code:
          webuse pig, clear
          generate week2 = week*week
          mixed weight week week2 || id: week week2
          predict u*, reffects
          codebook u*, compact
          /*
          Variable   Obs Unique       Mean        Min       Max  Label
          --------------------------------------------------------------------------------------------------
          u1         432     48  -1.07e-10  -1.380002  1.192608  BLUP r.e. for id: week
          u2         432     48  -7.88e-11  -.1280994  .1339894  BLUP r.e. for id: week2
          u3         432     48   4.00e-09  -3.592674  6.074069  BLUP r.e. for id: _cons
          */
          generate intercept = _b[_cons] + u3
          generate slope = _b[week] + u1 + _b[week2] + u2
          Last edited by Erik Ruzek; 20 Dec 2023, 12:23. Reason: Added dataset and code to create week2

          Comment


          • #6
            Erik Ruzek but how do i get intercept and slope from u1 u2 u3?

            Comment


            • #7
              Originally posted by Leon Edelman View Post
              What isn't clear? I specified the model and my issue. The error is that the predicted intercepts and slopes when I include week-squared doesn't make any sense.
              "Doesn't make any sense" isn't meaningful to me. Just like Erik presented a reproducible example, show the output and state what you mean. I would also use factor variable notation here.

              Code:
              webuse pig, clear
              mixed weight c.week##c.week || id: c.week##c.week
              predict u*, reffects
              sum u*
              Res.:

              Code:
              . mixed weight c.week##c.week || id: c.week##c.week
              
              Performing EM optimization ...
              
              Performing gradient-based optimization:
              Iteration 0:  Log likelihood = -851.98873  
              Iteration 1:  Log likelihood = -851.97882  
              Iteration 2:  Log likelihood =  -851.9788  
              
              Computing standard errors ...
              
              Mixed-effects ML regression                         Number of obs    =     432
              Group variable: id                                  Number of groups =      48
                                                                  Obs per group:
                                                                               min =       9
                                                                               avg =     9.0
                                                                               max =       9
                                                                  Wald chi2(2)     = 3201.24
              Log likelihood =  -851.9788                         Prob > chi2      =  0.0000
              
              --------------------------------------------------------------------------------
                      weight | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
              ---------------+----------------------------------------------------------------
                        week |   6.358818   .1299895    48.92   0.000     6.104043    6.613593
                             |
               c.week#c.week |  -.0148922    .012763    -1.17   0.243    -.0399073    .0101228
                             |
                       _cons |   19.08259   .3943525    48.39   0.000     18.30967    19.85551
              --------------------------------------------------------------------------------
              
              ------------------------------------------------------------------------------
                Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
              -----------------------------+------------------------------------------------
              id: Independent              |
                                 var(week) |   .3755398   .1376915      .1830473    .7704575
                            var(week#week) |   .0036763   .0013556      .0017845    .0075734
                                var(_cons) |   5.398871   1.355592      3.300475    8.831398
              -----------------------------+------------------------------------------------
                             var(Residual) |   1.275934   .1137477      1.071383    1.519538
              ------------------------------------------------------------------------------
              LR test vs. linear model: chi2(3) = 798.37                Prob > chi2 = 0.0000
              
              Note: LR test is conservative and provided only for reference.
              
              .
              . predict u*, reffects
              
              . sum u*
              
                  Variable |        Obs        Mean    Std. dev.       Min        Max
              -------------+---------------------------------------------------------
                        u1 |        432   -1.07e-10    .5025716  -1.380002   1.192608
                        u2 |        432   -8.00e-11    .0494083  -.1280994   .1339894
                        u3 |        432    4.00e-09    2.142611  -3.592674   6.074069

              Comment


              • #8
                Originally posted by Leon Edelman View Post
                Erik Ruzek but how do i get intercept and slope from u1 u2 u3?
                What do you mean by "get intercept and slope from u1 u2 and u3"? The code Andrew and I posted shows you how to get the 48 intercept values for each of the ids. What do you want to do with that information?
                Last edited by Erik Ruzek; 20 Dec 2023, 14:04. Reason: Grammar

                Comment

                Working...
                X