I teach statistics (undergraduate level). It's an introduction course to statistics and very basic. Something that I find very time-consuming is to create training data for the students.
I use the formula $X_3= (r \times X_1)+(\sqrt{(1 - r^2)} \times X_2$ to create data with different degrees of correlation. Using this equation I will get two variables $X_3$ and $X_2$ that has a correlations coefficient is $r$ (Choice by me). $X_1$ and $X_2$ are two randomly generated variables (same mean, standard deviation). So far no problem.
Does anyone have any idea how to easily create a data where the correlation between $X$ and $Y$ can be controlled away by adding variable $Z$? Usually I want to give students a task like; first make a regression analysis between $X$ and $Y$, interpret the results. Then add $Z$ (multivariate analysis). Does the impact of $X$ on $Y$ change when controlling for $Z$. ($Z$ is typically an mediating or confounding factor)
What I want to accomplish is a data where the relationship between $X$ and $Y$ disappears (completely or partially) when the students add $Z$. Someone who has a smart solution in an easy way to create such data?