Announcement

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

  • binary variable is not recognised as two separate groups in mixed model in stata

    mixed y x1 x2 x3 || group: || second: ,mle
    y is a continuous variable. Second is recognised as 5 groups, which is correct.
    Group should be recognised as two groups but is only recognised as one. It is a binary variable labelled as drug and control.

  • #2
    Right now you are trying to estimate a 3-level random intercepts mode, with group at the highest level and second at the 2nd level. Moreso, groups are being defined by the level of group and second.

    I wouldn't try to fit a random intercept for drug group, but instead include it as a fixed effect, and add a random intercept for the person's id. I don't know what -second- refers to so I won't comment on this unless you can report back a more full description of what model you are trying to fit and your experimental design.

    Code:
    * change the variable to match your own data
    mixed y x1 x2 x3 i.group || personid : , mle

    Comment


    • #3
      Thank you for the quick response Leonardo.

      In this case, there are a couple 100 people randomly assigned to two groups, 'group' drug or control. Those in the drug group could have received one of four types of treatment, that is the 'second' variable. A continuous outcome and a binary outcome was measured on four different occasions post randomisation.

      People in the drug group and the control group are also from two different 'location'. Those in the drug group in location1 could have had treatment1 or treatment2 and those in location2 - treatment3 or treatment4.
      I have already chosen to include 'location' as a fixed effect.

      I am trying to see the treatment effect for the two 'group' on the continuous outcome.

      Comment


      • #4
        Originally posted by Misha Ram View Post
        I am trying to see the treatment effect for the two 'group' on the continuous outcome.
        You can examine the treatment effect for both continuous and binary outcomes at once. The code below illustrates how. (Begin at the "Begin here" comment; the code above just creates a dataset that mimics yours in its major study design features.) Do-file and log file are attached.
        Code:
        version 18.0
        
        clear *
        
        // seedem
        set seed 216605583
        
        // "couple 100 people"
        quietly set obs 204
        generate int pid = _n
        generate double pid_u = rnormal()
        
        // "two different 'location'"
        generate byte loc = mod(_n, 2)
        
        /* "'group' drug or control" "location1 could have had treatment1 or treatment2
           and those in location2 - treatment3 or treatment4" */
        generate byte grp = mod(_n, 3)
        quietly recode grp (1=3) (2=4) if loc
        tabulate grp loc
        
        // "four different occasions post randomisation"
        quietly expand 4
        bysort pid: generate byte tim = _n
        
        // "A continuous outcome and a binary outcome was measured"
        generate double out1 = pid_u + rnormal()
        generate byte out2 = rbinomial(1, normal(pid_u))
        
        *
        * Begin here
        *
        gsem ///
            (out1 <- i.grp i.loc i.tim i.grp#i.tim i.loc#i.tim M[pid]) ///
            (out2 <- i.grp i.loc i.tim i.grp#i.tim i.loc#i.tim M[pid], probit), ///
                nocnsreport nodvheader nolog
        // Interaction terms
        testparm i.grp#i.tim
        testparm i.loc#i.tim
        // Main effects (i.loc is two groups, and so by inspection of regression output)
        testparm i.grp
        testparm i.tim
        
        exit
        I don't necessarily recommend it, but if you want to restrict your analysis to the continuous outcome, then you could do something like the following.
        Code:
        mixed out1 i.grp i.loc i.tim i.grp#i.tim i.loc#i.tim || pid: , nolrtest nolog
        contrast grp loc tim grp#tim loc#tim
        Attached Files

        Comment


        • #5
          Thank you Joseph for you very detailed response. This is really helpful.

          Comment

          Working...
          X