Announcement

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

  • Two-level random-slope model

    Dear Statalist community,

    I am using a two-level random-slope model and using the Bangladesh dataset as an example for my question.

    use http://www.stata-press.com/data/r15/bangladesh
    melogit c_use i.urban || district: urban


    I am looking for advice on how to extract the estimate (that incorporates the fixed and random effects) and standard error of urban for each district.

    Many thanks.
    Last edited by Dan Murphy; 01 Nov 2023, 08:23.

  • #2
    Code:
    predict u*, reffects reses(v*)
    des u* v*
    gen urban_effect = _b[c_use:1.urban] + u1
    // AND THE STANDARD ERROR IS IN v1

    Comment


    • #3
      Clyde's solution is spot on. Stepping back a bit, when estimating models with random slopes, analysts often allow the random effects to covary. Whether this is appropriate for the data can be evaluated by the use of a likelihood ratio test. In this case, the model fit of the model with an unstructured variance-covariance matrix for the random effects provides a better fit to the data.
      Code:
      melogit c_use i.urban || district: urban
      est sto no_cov
      
      predict u*, reffects reses(v*)
      des u* v*
      gen urban_effect = _b[c_use:1.urban] + u1
      
      melogit c_use i.urban || district: urban, cov(un)
      est sto cov
      
      predict uc*, reffects reses(vc*)
      des uc* vc*
      gen urban_effect_c = _b[c_use:1.urban] + uc1
      
      *test of model fit
      lrtest cov no_cov, stats 
      
      Likelihood-ratio test                                 LR chi2(1)  =     12.29
      (Assumption: no_cov nested in cov)                    Prob > chi2 =    0.0005
      
      Akaike's information criterion and Bayesian information criterion
      
      -----------------------------------------------------------------------------
             Model |          N   ll(null)  ll(model)      df        AIC        BIC
      -------------+---------------------------------------------------------------
            no_cov |      1,934          .  -1249.223       4   2506.446   2528.716
               cov |      1,934          .  -1243.079       5   2496.158   2523.994
      -----------------------------------------------------------------------------
      Comparing the estimates of the two different urban_effect variables, the distribution of predictions varies non-trivially. Accordingly, think carefully about which set of predictions are more relevant for your situation.
      Code:
      sum urban_effect*
      
          Variable |        Obs        Mean    Std. Dev.       Min        Max
      -------------+---------------------------------------------------------
      urban_effect |      1,934     .665147    .2960627   -.117348   1.376067
      urban_effe~c |      1,934    .7398765    .5705939  -.8973983   1.991332

      Comment


      • #4
        Thank you very much, Clyde and Erik.

        Comment

        Working...
        X