Announcement

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

  • Mixed Command

    Hello. Can someone please explain how does nesting in mixed command work? I have variables year, firm, business segment, profitability, industry.

    I am doing:
    egen corp_industry = group(firm industry)
    mixed profitability year || _all: R.industry || _all: R.firm || corp_industry: business_segment, reml.
    I would like business segment to be nested within cross classification of firm and industry. Is this correct way to model it? I want year to be fixed effect, other variables to be random effects.

    Thanks in advance

  • #2
    Originally posted by Alinur Beisenbay View Post
    I have variables year, firm, business segment, profitability, industry.. . . I would like business segment to be nested within cross classification of firm and industry. . . . I want year to be fixed effect, other variables to be random effects.
    I believe that it would be more like this:
    Code:
    mixed profitability i.year || _all: R.industry || _all: R.firm || business_segment:
    You can always use a simulated dataset to check things.
    Code:
    version 19
    
    clear *
    
    // seedem
    set seed 1205695088
    
    /* A and B cross-classified */
    quietly set obs 20
    generate byte a = _n
    generate double a_u = rnormal()
    
    tempfile as
    quietly save `as'
    
    drop _all
    quietly set obs 20
    generate byte b = _n
    generate double b_u = rnormal(0, 2)
    
    cross using `as'
    
    /* C nested under the A-B categories */
    quietly expand 5
    sort a b
    generate int c = _n
    generate double c_u = rnormal(0, 4)
    
    quietly expand 3
    bysort a b c: generate byte t = _n
    
    generate double out = rnormal(a_u + b_u + c_u, 8)
    
    *
    * Mixed model
    *
    mixed out i.t || _all: R.a || _all: R.b || c:
    
    exit

    Comment


    • #3
      Thank you so much for your reply Joseph. I agree that year should be categorical and I need to include i.year instead of just year. But what about business_segment, I believe if I model using the code you provided, business segment will not be nested within cross-classification of industry and firm since by writing _all: R. we are saying that everything to the right of it will be cross-classified structure.

      As far as I know there is no difference between

      mixed a || _all: R.b || _all: R.c and mixed a || _all: R.b || c: Thank you in advance.

      Comment


      • #4
        Originally posted by Alinur Beisenbay View Post
        . . . I believe if I model using the code you provided, business segment will not be nested within cross-classification of industry and firm since by writing _all: R. we are saying that everything to the right of it will be cross-classified structure.
        It will be cross-classified if all values (categories) of business segment are represented in each pair of industry-firm values (categories), but I believe that it will be modeled as nested despite the _all: if each pair of industry-firm values has its own exclusive set of business segment values.

        Notice in the code that I provided above in #2 that values of c are not shared among the a-b pairs, that is, I coded
        Code:
        sort a b
        generate int c = _n
        and not
        Code:
        bysort a b: generate byte c = _n
        so that each pair of a-b values has its own exclusive (i.e., nested) set of c values.

        As far as I know there is no difference between

        mixed a || _all: R.b || _all: R.c and mixed a || _all: R.b || c:
        Yes, in that both of your syntax examples represent an interaction of the two random-effects variables, but I don't think that _all: R. is synonymous with "everything to the right of it will be cross-classified".

        I illustrate below using your two syntax examples, but with a dataset where the c level is nested under (not crossed with) the b level in line with my code example above.
        Code:
        version 19
        
        clear *
        
        // seedem
        set seed 641822407
        
        quietly set obs 20
        generate byte b = _n
        generate double b_u = rnormal()
        
        quietly expand 20
        sort b
        generate `c(obs_t)' c = _n
        generate double c_u = rnormal(0, 2)
        
        quietly expand 3
        
        generate double a = rnormal(b_u + c_u, 4)
        
        mixed a || _all: R.b || _all: R.c , nolrtest nogroup nolog
        
        mixed a || _all: R.b || c: , nolrtest nogroup nolog
        
        mixed a || b: || c: , nolrtest nogroup nolog
        
        exit
        Both of your _all: R. syntax examples—the first & second shown here—fit the same model. But that model is the same as that fitted by the conventional nested syntax—the third shown here. So, yes, there is no difference (they're both basically interaction terms), but here they're both modeling a nested structure, and not crossed versus nested. Do-file and its log file are attached below for your convenience.

        If your business segment variable is like that, that is, if each pair of industry-firm values does not share its set of business-segment values, then I believe that my syntax above in #2 will fit the model that you're seeking.
        Attached Files

        Comment

        Working...
        X