# How to test whether the association between two continuous variables varies by a third variable?

If I have two continuous variables, and want to check whether their association varies by a categorical variable (e.g. gender), is there a formal statistical test for this?

I know I can create a linear model in R and add an interaction term to the model, but I wanted to check whether there's a statistical test for association between two variables stratified by a third.

Moreover, is there something like the Pearson Correlation coefficient, but stratified by a third categorical variable?

I don't know about formal tests, but anyhow I would start with visualization. R has a function coplot which is convenient for this, and can be used to condition on one or two variables. Examples can be found in multiple posts, see Investigate correlation conditional on a threshold and Can I analyze or model a conditional correlation? and What is the physical significance of cumulative correlation coefficient?
As for inference, links in Can I analyze or model a conditional correlation? can be helpful. I have found very little published about conditional correlations. One reason can be the following: Look at a random vector $$(X,Y,Z)$$ with multivariate normal distribution. Then, in the conditional distribution of $$(X,Y)$$ given $$Z=z$$, the correlation of $$X, Y$$ do not depend on $$z$$, it is always a constant. The proof is a simple exercise in matrix calculations. Since much of descriptive statistics historically was informed by the normal distribution, conditional correlation was not a natural topic.