Announcement

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

  • Convert SAS PROC MIXED to Stata code

    Hi all, I'm not sure that this is the best forum for this question but am not sure of another one. I need to convert SAS code from PROC MIXED to Stata code. Here is the SAS code:

    Code:
    proc mixed data=data1 noclprint method=reml covtest;
    
    class batch bor mol pop var1 var2 var3;
    
    model dep = var1 var2 var3 / solution;
    
    random intercept / sub=pop type=un S G;
    
    random intercept / sub=mol type=un S G;
    
    random intercept / sub=bor type=un S G;
    
    run;


    Here is the Stata code I have come up with. It doesn't give exactly the same results. I noticed part of the SAS code specifies type=un, which refers to an unstructured, that is, arbitrary covariance matrix. Is there an equivalent Stata option for that, maybe that is why the results don't match? Or maybe there is something else wrong with my Stata code? I'm not sure I got the random effects right.


    Code:
    mixed dep var1 var2 var3 || _all: R.bor || _all: R.mol || pop:, reml
    Any advice much appreciated.

  • #2
    The last time I used SAS, PROC MIXED had not yet been invented. So I can't say if your model matches the SAS code or not. What I can tell you is that if you want an unstructured (arbitrary) covariance matrix for the random effects, just add -cov(un)- at the end of the -mixed- command.

    I can also add that your Stata command has bor, mol,and pop as crossed random effects.

    Comment


    • #3
      I have used SAS a bit more recently than Clyde, but I'm not very familiar with PROC MIXED either. I will say that 3 separate RANDOM statements implies 3 crossed random effects to me, and specifically, 3 crossed random intercepts for pop, bor, and mol. If so, the Stata syntax looks to be equivalent, minus the covariance structure. You didn't specify a covariance structure between random effects, so Stata assumed independent. I am not as familiar with crossed random effects in Stata, but the syntax looks correct.

      Also, most properly, if you prefix var1-var3 with the i. notation for factor variable syntax, it will treat them as factor variables. By including them in the CLASS statement, you told SAS to treat them as factor variables. By not prefixing them with the i. syntax in Stata, they get treated as continuous variables. This may be irrelevant if they're binary variables. If they were categorical, then that's a problem.

      Code:
      mixed dep i.var1 i.var2 i.var3 || _all: R.bor || _all: R.mol || pop:, reml
      All caps for command names and statement names is SAS convention, which I repeat here. You will almost surely have noticed that Stata is case sensitive and almost always written in lower case (except for the R. notation in random effects). I'll repeat it just in case someone else is reading this and has been tripped up.
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment


      • #4
        Thank you! This is very helpful!!

        Comment

        Working...
        X