Announcement

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

  • Nested and Crossed Random Effects Model

    Dear all,

    I am currently working on a project where we aim to estimate a random effects models. Unfortunately, I cannot share the data or make an example using dataex as it is confidential. However, our data takes on the following form:
    Factor1 (level 1) is nested within Factor2 (level 2). On level 3, we have two different factors, i.e., factor3a and factor 3b. Factor 3a is nested within factor 2, which is nested in factor 1. Factor 3b is also nested within factor 2 (which is nested in factor 1). Factor 3a and factor 3b are not nested within each other, i.e., to my understanding they are cross-nested.

    After consulting the syntax, I tried to implement this structure using the following code:

    Code:
    mixed Y|| factor1: || factor2: || _all: R.factor3a || factor3b:, var  mle
    (1)

    However, I always get an error code "3900 unable to allocate real <tmp>" when running the code with the full set of data (around 17'000 obs.; ). The model runs if the "R." in front of "factor3a" is omitted, i.e.,

    Code:
    mixed Y|| factor1: || factor2: || _all: factor3a || factor3b:, var  mle
    (2)

    However, then, factor 3a and factor 3b are not cross-nested, to my understanding.

    Unique factors: Level 1: 239; Level 2: 2'079 unique factors; Level 3a: 3'817; Level 3b: 12'423

    Hence, the following question: Does the proposed code (1) capture my intended model, i.e., that factor 3a and factor 3b are cross-nested, and both are nested within factor 2, which is nested in factor 1? If so, any idea how the estimation could work?

    Best regards,
    Pascal

  • #2
    Originally posted by Pascal Meier View Post
    Factor 3a is nested within factor 2, which is nested in factor 1. Factor 3b is also nested within factor 2 (which is nested in factor 1). Factor 3a and factor 3b are not nested within each other, i.e., to my understanding they are cross-nested.
    Not necessarily. If your lowest level (so-called unit of observation) is not represented in both, then they're just nested.

    Unique factors: Level 1: 239; Level 2: 2'079 unique factors; Level 3a: 3'817; Level 3b: 12'423
    I cannot understand the structure of your dataset from that, but you might have just a four-level hierarchical model, with factors 3a and b at the penultimately lowest level.

    I cannot share the data or make an example using dataex as it is confidential.
    Then create and attach a phony dataset that captures the essential features of the real dataset (especially the relationship between the various levels or factors) that you have a questions about how to model.

    (Or—in lieu of attaching the phony dataset that it creates—show the Stata code that implements the data-generating process that you're trying to model.)

    Comment


    • #3
      Originally posted by Joseph Coveney View Post
      Not necessarily. If your lowest level (so-called unit of observation) is not represented in both, then they're just nested.

      I cannot understand the structure of your dataset from that, but you might have just a four-level hierarchical model, with factors 3a and b at the penultimately lowest level.

      Then create and attach a phony dataset that captures the essential features of the real dataset (especially the relationship between the various levels or factors) that you have a questions about how to model.

      (Or—in lieu of attaching the phony dataset that it creates—show the Stata code that implements the data-generating process that you're trying to model.)
      Thanks for your fast answer, Joseph. I try to give a fictitious example that should capture the core of our data structure.

      The highest level (unit of observation; level 1) is "ZIPCode" (unique ID). The next unit of observation is "School" (level 2; unique ID). "School" is nested within "ZIPCode". On level 3, we have two units of observation: "Teacher" (unique ID) and "Class"(unique ID). Both "Teacher" and "Class" are nested within "School". "Teacher" and "Class" are not nested within each other, i.e., they are on the same level.

      Would this code be appropriate to model this relationship? Otherwise, I try to create a pseudo dataset.

      mixed Y|| ZIPCode: || School: || _all: R.Class|| Teacher:, var mle
      Thanks and best regards,
      Pascal

      Comment


      • #4
        Do you mean that there are 239 ZIP codes that contain about eight or nine schools each (total 2079)? That each school is represented in your dataset by fewer than two classes on average (total 3817)? And that each class on average is taught by more than three teachers (total 12,423)? Is the problem that you're not able to associate any teacher with any particular class or set of classes taught (data not recorded)?

        Is teacher the lowest (most granular) level, or are there students within teacher (or teacher-class combinations), perhaps multiple observations (beginning of term, midterm and end of term) on each student? That is, what forms the basis for estimating (and distinguishing) the variance component of class? Of teacher?

        All of this aside, with more than twelve thousand IDs for one random effect and nearly four thousand for the other, then you might have difficulty in Stata accommodating that many in a cross-classified random effects model. And if there is a one-to-one correspondence (one class per teacher), then with such an imbalance in the counts, it means that there will be a majority of singletons for the teachers—again, I really do not understand the structure of your dataset, what you've got, so I'm just guessing here.

        Comment

        Working...
        X