Announcement

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

  • Mixed: fixed intercept random slope

    I am trying to run the mixed command and set it to have a fixed intercept and random slopes. In other words, I am starting with this:

    Code:
    mixed y a b || ID: a b
    and I want to modify it so that the slopes of a and b are allowed to vary but the intercept is fixed. I found an old thread on this, but in that thread "ID:" was taken out and replaced by a:, which does not tell Stata what the nesting structure is. So I think that solution is probably wrong.


  • #2
    I don't think there is any way to do this with -mixed-. However, you can emulate multilevel models using -gsem-:
    Code:
    gsem (y <- a b a#L1[ID]  b#L2[ID])
    would give you random slopes at the ID level without random intercepts there. Be sure to specify appropriate c. or i. prefixes to a and b (and their appearances in the interactions with the latent variables) so they are appropriately handled as either continuous or discrete.

    That said, I have never seen a model that used random slopes without random intercepts, and I am unable to imagine a problem for which that would be the solution. Would you mind explaining what the context is? I'm curious.

    Comment


    • #3
      If you include indicators on the left-hand side, you may be able to achieve what you want. Below, although Stata will show an estimate of the variance of the random intercept, it is effectively zero.

      Code:
      webuse grunfeld, clear
      mixed invest mvalue kstock i.company|| company: mvalue
      Res.:

      Code:
      . mixed invest mvalue kstock i.company|| company: mvalue
      
      Performing EM optimization: 
      
      Performing gradient-based optimization: 
      
      Iteration 0:   log likelihood = -1071.3474  
      Iteration 1:   log likelihood = -1071.1349  
      Iteration 2:   log likelihood = -1071.1186  
      Iteration 3:   log likelihood = -1071.1185  
      
      Computing standard errors:
      
      Mixed-effects ML regression                     Number of obs     =        200
      Group variable: company                         Number of groups  =         10
      
                                                      Obs per group:
                                                                    min =         20
                                                                    avg =       20.0
                                                                    max =         20
      
                                                      Wald chi2(11)     =     470.23
      Log likelihood = -1071.1185                     Prob > chi2       =     0.0000
      
      ------------------------------------------------------------------------------
            invest |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            mvalue |   .0742195   .0221198     3.36   0.001     .0308654    .1175736
            kstock |   .3057698   .0161507    18.93   0.000     .2741151    .3374245
                   |
           company |
                2  |   230.5893   76.86353     3.00   0.003     79.93952     381.239
                3  |   81.04043   69.95378     1.16   0.247    -56.06645    218.1473
                4  |   164.4117   59.19399     2.78   0.005     48.39359    280.4298
                5  |   72.28138   56.69834     1.27   0.202    -38.84533    183.4081
                6  |   161.4929   55.89953     2.89   0.004     51.93183     271.054
                7  |   107.9815   55.88235     1.93   0.053    -1.545908    217.5089
                8  |   151.4123   57.93884     2.61   0.009     37.85423    264.9703
                9  |   97.57298   56.47861     1.73   0.084    -13.12307     208.269
               10  |   163.8074   54.77487     2.99   0.003      56.4506    271.1642
                   |
             _cons |  -167.7976   53.86745    -3.12   0.002    -273.3758   -62.21932
      ------------------------------------------------------------------------------
      
      ------------------------------------------------------------------------------
        Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
      -----------------------------+------------------------------------------------
      company: Independent         |
                       var(mvalue) |   .0015405   .0016774      .0001823    .0130163
                        var(_cons) |   3.22e-09          .             .           .
      -----------------------------+------------------------------------------------
                     var(Residual) |   2368.315   253.3288      1920.393    2920.714
      ------------------------------------------------------------------------------
      LR test vs. linear model: chi2(2) = 0.00                  Prob > chi2 = 1.0000
      
      Note: LR test is conservative and provided only for reference.
      
      .

      Comment


      • #4
        The situation I have, which I haven't encountered before, is that the variance of the intercept is effectively zero. I therefore wanted to constrain it to zero. I realize that's not necessary but it is something that is allowed in HLM7 so I thought I'd look for an equivalent in Stata.

        Comment


        • #5
          Andrew Musau That's very interesting. I've never seen that before. Is it documented somewhere? Does it always work? Does it have any tendency to create convergence problems (estimating variance components close to zero can be very difficult)? And does it play with -margins-?

          Comment


          • #6
            Clyde, I have not seen this documented. I encountered it previously following some users including panel and time dummies and wanting to estimate a random intercept model. Later on, they complain that their estimates do not differ from a two-way fixed effects model.Of course, you cannot have both.

            Comment


            • #7
              Andrew Musau , a slight tweak to your suggestion is to add a -nocons- constraint to the 2nd level of mixed.

              Code:
              . mixed invest mvalue kstock i.company|| company: mvalue, nocons nolog
              
              Mixed-effects ML regression                     Number of obs     =        200
              Group variable: company                         Number of groups  =         10
                                                              Obs per group:
                                                                            min =         20
                                                                            avg =       20.0
                                                                            max =         20
                                                              Wald chi2(11)     =     470.23
              Log likelihood = -1071.1185                     Prob > chi2       =     0.0000
              
              ------------------------------------------------------------------------------
                    invest | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                    mvalue |   .0742185   .0221203     3.36   0.001     .0308634    .1175735
                    kstock |   .3057698   .0161506    18.93   0.000     .2741152    .3374245
                           |
                   company |
                        2  |   230.5874   76.86427     3.00   0.003     79.93623    381.2386
                        3  |   81.04454   69.95419     1.16   0.247    -56.06314    218.1522
                        4  |   164.4136   59.19439     2.78   0.005     48.39475    280.4325
                        5  |   72.28369   56.69845     1.27   0.202    -38.84323    183.4106
                        6  |   161.4947   55.89969     2.89   0.004     51.93331    271.0561
                        7  |   107.9831   55.88244     1.93   0.053    -1.544484    217.5106
                        8  |    151.415   57.93912     2.61   0.009      37.8564    264.9736
                        9  |   97.57502    56.4788     1.73   0.084    -13.12139    208.2714
                       10  |   163.8089   54.77493     2.99   0.003     56.45201    271.1658
                           |
                     _cons |   -167.799   53.86749    -3.12   0.002    -273.3774   -62.22067
              ------------------------------------------------------------------------------
              
              ------------------------------------------------------------------------------
                Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
              -----------------------------+------------------------------------------------
              company: Identity            |
                               var(mvalue) |   .0015406   .0016775      .0001823    .0130168
              -----------------------------+------------------------------------------------
                             var(Residual) |   2368.309   253.3274      1920.389    2920.704
              ------------------------------------------------------------------------------
              LR test vs. linear model: chibar2(01) = 0.00          Prob >= chibar2 = 1.0000

              Comment


              • #8
                Perfect Leonardo Guizzetti!

                Comment


                • #9
                  Originally posted by Chris Martin View Post
                  it is something that is allowed in HLM7
                  I’m curious: does HLM7’s documentation say anything about its motivation or when it’s appropriate?

                  The concept of a random slope against a fixed intercept would seem to go against ANOVA precedent, which holds that the term for the interaction of two fixed factors (predictors) is itself fixed, but that for the interaction of a fixed factor and a random factor is random. A random slope is the interaction term of a fixed effect (a or b in your case) and a random effect (ID in your example), and so it seem inconsistent to keep an ID × a interaction term as random (random slope), yet insist that both of its components be treated as fixed.

                  And about the ID’s variance being essentially zero while that of its interactions involving a or b are nonzero, wouldn’t that situation depend entirely upon where you happen to have centered the scale of the a or b predictors, the same as in any categorical-by-continuous interaction? That is, shift the scale of a or b rightward or leftward a little, and the intercept is bound to have nonzero variance if there is any slope to the continuous predictor at all.

                  Comment


                  • #10
                    One example that comes to mind is a situation where the intercept is zero. If both x and y are ratio variables with a meaningful null value, x is input, and y is output, you may expect a fixed intercept of zero. If you google "fixed intercept, random slope" you can find articles and chapters with interesting examples.

                    Comment


                    • #11
                      The LL and chi-square values are the same regardless of nocons here. That suggests that the underlying model is the same, doesn't it? Perhaps that happens when the intercept is effectively zero, which is the result of Andrew's method of including i.company.




                      Originally posted by Leonardo Guizzetti View Post
                      Andrew Musau , a slight tweak to your suggestion is to add a -nocons- constraint to the 2nd level of mixed.

                      Code:
                      . mixed invest mvalue kstock i.company|| company: mvalue, nocons nolog
                      
                      Mixed-effects ML regression Number of obs = 200
                      Group variable: company Number of groups = 10
                      Obs per group:
                      min = 20
                      avg = 20.0
                      max = 20
                      Wald chi2(11) = 470.23
                      Log likelihood = -1071.1185 Prob > chi2 = 0.0000

                      Comment


                      • #12
                        Yes, including -nocons- gives you a cleaner result. As you state, it has no effect on the estimates as the variance of the random intercept is zero. I believe this achieves what you want. Maybe try and see if you obtain the same results with the other software package that you reference.

                        Comment


                        • #13
                          Hi! I'm going through the same problem. Has anyone got the answer yet?
                          Plz help!

                          Comment


                          • #14
                            In case anyone is interested, I ran across a paper that suggests this approach in cases where treatment assignment varies within clusters and one is interested in exploring treatment effect heterogeneity. The model they propose is the following:
                            Code:
                            mixed out i.trtmt i.cluster || cluster: i.trtmt, nocons residuals(independent, by(trtmt))
                            They argue that there maybe cluster-specific decisions about who gets assigned to treatment that one wants to account for that are correlated with treatment effectiveness. The fixed intercepts are supposed to help with this. The independent residuals by treatment group are also argued to help within-cluster differences in outcomes. They utilize random (or varying) slopes and empirical Bayes shrinkage to get more reliable estimates of cluster-level treatment effects than one would get from:
                            Code:
                            reg out i.trtmt##i.cluster
                            Last edited by Erik Ruzek; 16 Sep 2024, 10:15. Reason: Fixed syntax

                            Comment

                            Working...
                            X