BookmarkSubscribeRSS Feed
oskarseriksson
Calcite | Level 5

Hello,

I'm about to perform an analysis with two levels, something I have never done before in SAS and to be honest it's been a couple of years since my last multilevel analysis.

I have to levels, REGIONAL and LOCAL, where the latter is (obviously) a subgroup of the former. My dependent variable is Y and my control variables are A and B, i. e. y = intercept + a + b + error, on two levels.

I want both the intercept and the coefficients to be "random", and when I have done that I want to be able to measure the adjusted explanatory power on both levels in order to find out how much is explained on each level. I could settle with just letting the intercept vary.

I have given it a couple of shots with PROC GLM and PROC GLIMMIX and PROC MIXED but I haven't done it right yet because my outputs look weird and my results are completely ridiculous.

What code would you use?

Merry xmas to you, fellow SAS-users!

O

6 REPLIES 6
SteveDenham
Jade | Level 19

Depending on the characteristics of the dependent variable Y, I would use either PROC MIXED or PROC GLIMMIX, and since you can do almost everything that MIXED does in GLIMMIX, plus more, I offer the following code;

proc glimmix data=yourdata;

class A B regional local subjid; /* Assumes that the control variables are categorical.  If not, we will address as you provide more information */

model y=A B A*B/solution; /* Fixed effects */

random regional regional*local/subject=subjid s; /* Multiple level data random effects */

random intercept A B A*B/subject=subjid(regional local) s; /*Random slopes and intercepts for the control variables and their interaction */

Good luck.

Steve Denham

oskarseriksson
Calcite | Level 5

Hi Steve!


Y is continuous. The control variables A and B are also continuous.


I'll start with the code you provided and I look forward to more input from you! You are really helpful and I appreciate it.

On the future results of this analysis; need any of the variables be normally distributed or is it just the residuals that need be normally distributed? I have heard different opinions from fellow statisticians.

Happy holidays,


Oskar

SteveDenham
Jade | Level 19

Well, if A and B are both continuous, that does change some things.  Any interaction would have to be created in a programming step.

New (untested) code:

proc glimmix data=yourdata;

AB=A*B;

class regional local subjid; /* Assumes that the control variables are categorical.  If not, we will address as you provide more information */

model y=A B AB/solution; /* Fixed effects */

random regional regional*local/subject=subjid s; /* Multiple level data random effects */

random intercept A B AB/subject=subjid(regional local) s; /*Random slopes and intercepts for the control variables and their interaction */

run;

I would strongly suggest zero centering A and B in a data step prior to the proc, and if you are going to do that, you might as well define AB in the data step as the product of the zero centered A and B.

Steve Denham

oskarseriksson
Calcite | Level 5

Hi!

I used the PROC MIXED-code provided in the paper Adam1 referred to, and it worked. For some reason, I never got the interactions to work out when I used the code you wrote. Odd. However, the control variables weren't crucial to my analysis as I was mainly looking for the explained variation in one of my levels.

Thanks for being helpful!

Adam1
Calcite | Level 5

Among many tutorials on this topic, I think you would find this one helpfull: http://support.sas.com/resources/papers/proceedings13/433-2013.pdf

It describes multilevel models in proc mixed with 4 examples, both organizational and growth models.

oskarseriksson
Calcite | Level 5

Thank you!

I used the PROC MIXED-code provided in the paper and it worked out perfectly. The paper was also very pedagogical and clear in its methodology, which helped a lot.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1851 views
  • 9 likes
  • 3 in conversation