Announcement

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

  • Extract level means for each group after using "mixed"

    Dear Statalisters,

    I am trying to extract group level means after using the mixed command.

    Let me be more explicit: suppose there is a cross-sectional dataset constructed from a well-executed survey of pupils (10,000 observations) attending various schools (400 schools) in multiple counties (150 counties). That data has a three-level structure. Let's assume that my variable of interest is average_height. I could estimate the average height of pupils in each county, while taking into account the survey structure by estimating the following equation (assume that sampling_probability is the probability that a given pupil has been sampled for the survey):

    Code:
    mixed average_height [pweight=1/sampling_probability] || county: || school:, mle
    How can I extract the estimated average heights for each of the 150 counties? I am looking to obtain 150 averages, one for the average height of the pupils attending schools in each of the 150 counties.

    Thank you!

  • #2
    See

    Code:
    help mixed_postestimation
    for the options available for predict after mixed. The following will give you the prediction corresponding to the -xb- option described below:

    xb - linear prediction for the fixed portion of the model only; the default

    Code:
    mixed average_height [pweight=1/sampling_probability] || county: || school:, mle
    margins, over(county)
    Last edited by Andrew Musau; 27 May 2022, 06:45.

    Comment


    • #3
      Thank you for the quick response, Andrew.

      I attempted using the code you suggest, but the table it displays after running it gives me the exact same figure for each of the counties, which seems highly unlikely. What I mean to say is, using the same example, that the output to "margins, over(county)" tells me that the average height for the pupils in each county is exactly the same for all of the 150 counties (including S.E. and C.I).

      Comment


      • #4
        I had not noticed that you did not have any regressors in your model. With no regressors, what you get is an intercept and therefore, the prediction is constant as you observe. It appears that you want to include a constant for each county, but that is fixed effects. You cannot have both fixed effects and random effects for counties, these are mutually exclusive. So estimating an intercept for each county and with a random intercept for schools:


        Code:
        mixed average_height i.county [pweight=1/sampling_probability] || school:, mle
        margins i.county
        To my point above, notice that the estimated variance component corresponding to county is effectively zero if you attempt to include both county fixed and random effects,

        Code:
        mixed average_height i.county [pweight=1/sampling_probability] || county: || school:, mle
        and the estimates do not differ from those in the first specification.
        Last edited by Andrew Musau; 27 May 2022, 08:54.

        Comment


        • #5
          Code:
          predict height, reffects relevel(county)
          Will give you estimates of county level random effects

          Comment


          • #6
            Andrew Musau, I am not attempting to estimate the fixed effects from the model; I am interested in the county level random effects, because I am concerned that the estimates of the fixed effect values (the average heights produced by these) are likely to be too imprecise.

            DJ McArthur, thank you for your response. I had not noticed that calling the variable in my example average_height makes no sense as it measures the height of a single pupil. Your code seems to work perfectly. My code now looks something like this:

            Code:
            mixed height [pweight=1/sampling_probability] || county: || school:, mle
            predict average_height_intercept, reffects relevel(county)
            Now, if I understand correctly how to obtain the county level averages from the estimates that are stored in average_height_intercept, would I then have to add these to the _cons value (the grand-mean)? In the code below assume _cons = 1.5

            Code:
            gen county_average_height = average_height_intercept + _cons
            Last edited by Alvaro Gallegos-Jurado; 27 May 2022, 11:15.

            Comment


            • #7
              Maybe:

              Code:
              predict wanted, fitted relevel(county)

              Comment

              Working...
              X