How is clustered data and correlated data related? I am confused about the connection between clustered data and correlated data. Let's say we have a two-level data where level 1 refers to students and level 2 refers to schools. I assume we can also describe this setting as students who go to the same school are correlated. So, does the idea of correlation come from students within the same school?
If I were to generate data (in R) that has a list of students along with schools they are attending, then how do I approach it?
Thank you!
 A: Context
First, I want to apologise if the post is longer than expected: I started writing and tried to provide a detailed answer. Also, I will concentrate on answering the first conceptual part of the question. As it was noted, suppose we have a one-stage cluster design, with students clustered within their respective schools. In this case, schools are referred to as Primary Sampling Units, while students represent Secondary Sampling Units. 

What is the Intraclass correlation?
What I think you are referring to is called the Intra-class correlation $\rho$ (Kish, 1965). The Intra-class correlation measures the degree to which individuals are similar (homogenous) within their respective clusters (groups). So in your case, $\rho$ would measure how similar students are within their schools. 

How to calculate the Intraclass correlation?
It is calculated as: 
$$\rho = \frac{\sigma_b{^2}}{\sigma_b{^2} + \sigma_w{^2}}$$
Where $\sigma_b{^2}$ is between-cluster variance and $\sigma_w{^2}$ is the within-cluster variance. So essentially, $\rho$ is the proportion of the between-cluster variance to total variance. 
$$\rho = \frac{between\ cluster\ variance}{total\ varince}$$

Interpretation of the Intraclass correlation


*

*From the formula above, $\rho$ cannot be negative, and it ranges from $0$ to $1$. 

*In an ideal theoretical situation, in which $\rho = 1$ all responses within a cluster are identical. 

*A very small value for $\rho $ indicates that the within-cluster variance is considerably greater compared to the between-cluster variance.

*Note that in most practical cases, $\rho$ takes small positive values (Heeringa, West, & Berglund, 2010). 

*When $\rho = 0$ there is no correlation of responses within a cluster. 

Additional sources
To get a deeper insight into Clustering and the concept of the Intra-class correlation, I would recommend this wikipedia page, and this handout from the John Hopkins School of Public Health.  

TLDR
The Intra-class correlation $\rho$ measures the degree to which individuals are similar (homogenous) within their respective clusters (groups).
$\rho$ closer to $0$ means that there is no correlation of responses within a cluster
$\rho$ closer to $1$ means that responses within a cluster are perfectly correlated
In real life most $\rho$ values tend to be small, meaning that between-cluster variance is small, but within-cluster variance is large  

References:
Heeringa, S. G., West, B. T., & Berglund, P. A. (2010). Applied survey data analysis. London: CRC Press.
Kish, L. (1965). Sampling organizations and groups of unequal sizes. American Sociological Review, 564-572.
