# How to add features of the 2nd level into a multi-level regression?

My dataset contains variables of two levels, say individuals and regions. Each level has features. Note that the level2 features are repeated within each level2_ID.

example_data <- data.frame(level1_ID = c(1, 2, 3, 4, 5),
level1_depend = c(17, 32, 27, 30, 31),
level1_feat1 = c(21, 45, 25, 34, 32),
level1_feat2 = c(32, 67, 35, 41, 43),
level2_ID = c(1, 1, 2, 2, 2),
level2_feat1 = c(27, 27, 32, 32, 32),
level2_feat2 = c(11, 11, 14, 14, 14))


I would like to add the features of level2 as predictors in the model as well. Adding them as blocks in the model like this:

lmer(level1_depend ~ level1_feat1 + level1_feat2 + (level2_feat1 | level2_ID),
data = example_data)


seems not to be right, because the level2 features are constant in each level2_ID value. How do I add the level2 features appropriate?

Thanks for helping!

lmer(level1_depend ~ level1_feat1 + level1_feat2 + level2_feat1 + level2_feat2 + (1 | level2_ID), data = example_data)
This would be a model in which level1_depend is a function of two level-1 predictors, two level-2 predictors, with intercepts for level-2 varying. Note if your data are not already in this form, you will need to have each level-1 observation within each cluster of level-2 have the same values for the level-2 predictors.