How to identify suitable variables to assess confounding, mediation and effect modification? Imagine that you are planning a study about risk behaviours among HIV positive injecting drug users.
All the individuals included in the sample are injecting drugs and all are HIV positive. The main “exposure” in the study is the person’s awareness about their HIV serostatus (some of the drug users do know that they are HIV positive and some don’t know). The outcome is having had unprotected intercourse during the past 4 weeks.
Your imaginary study has not been performed yet and you are planning for data collection.
Which variables (age, place of living, relationship status, education etc, you can choose whatever variables you think are relevant) would you like to add in the data in order to assess confounding, mediation and effect modification of the association of interest in the study? 
 A: Your question is actually a very hard one to answer. It is however good that you are asking before the study has been conducted - preferably well before the study is conducted. So this answer comes in a few parts:


*

*As many as you can possibly collect, given constraints of time and money. There is (almost) no such thing as too much data, and its harder to collect a variable you realized you needed after the fact than to ignore a variable in your data.

*Read the literature. What are similar studies including? This has two different reasons behind it. First, those authors thought about what variables to include in their study, and there's no reason not to co-opt their work and expertise for your own ends. Second is to get a feel for what are standard, "must have" variables in your study that, if they're missing, you may get reviewer blowback for.

*Do you own a copy of Modern Epidemiology, 3rd Edition by Rothman, Greenland and Lash (Amazon link)? You should if you're considering running this kind of study. You may find Chapters 9 & 12 to be illuminating. Especially Chapter 12, on causal diagrams, which can be used as a study planning tool to identify sets of confounders you will likely need to control for.

*Read up on the use of Directed Acyclic Graphs as study planning tools - again, Chapter 12 of Modern Epi 3. A Google search for "DAG Confounding" will yield a wealth of potential resources. Once you have a feel for how they work, sit down with the rest of your study team - preferably in a room with a very large white board - and start making a causal diagram for your study. Try to work everything you can into the graph, then reduce it down, because again, it's better to overshoot than miss. There are software tools like Dagiity to help with the more labor intensive parts of the analysis.


Planning for potential confounding and effect modification is a long process that relies fairly heavily on subject matter expertise. Make sure you have a good team. If you don't feel like you do, or could use more, see if someone in your department or organization can help you out - there are lots of HIV/AIDS epidemiologists out there. I can think of some variables I would think are important (number of sexual partners, access to testing facilities, etc.) but you'd be better served by understanding the process rather than just having a list.
A: @EpiGrad has a really nice answer here.  I will try to throw in a few points that are hopefully useful and complementary.  
(By the way, @Mimi, you should click the check next to an answer.  You have asked for help, and people have spent their time to help you.  It's polite to acknowledge that your question has been answered.  My apologies for sounding preachy.  I can delete this paragraph later.)
It depends on what your goals are.  For example, you may want to predict the value of some variable given some information; alternatively, you may just want to understand the forces at work within this dynamic.  The latter goal is necessarily tied up with issues of causality, whereas prediction can ignore causality.  It would be perfectly reasonable for people in public health (say, in a government agency or a social worker, etc.) to want to be able to predict something like this.  It is possible to predict an effect from a cause, or a cause from an effect, or one effect from another effect, etc.  Should this be your goal, you want to gather the covariates that such users of your prediction model will have access to.  Not much else really matters.
On the other hand, if you want to understand this dynamic, you must come to understand the underlying causal pattern.  You should know that this is not remotely an easy task.  You should do the things that EpiGrad recommends; however, you need to know that they do not guarantee that your estimate of the relationship between AIDS awareness and unprotected sex is an unbiased estimate of the true causal relationship.  Determining other possible variables and partialling them out will only yield an unbiased estimate if the list of variables you come up with constitutes all the relevant variables.  It is very possible that there are relevant variables that no one has ever thought of yet.  Because regression methods assume predictor variables are measured without error (all error variability is considered part of the response variable) these other, unthought-of variables will be collapsed into the response variable's error term.  This causes the problem of endogeneity.  Any good econometrics book will discuss these issues extensively.  Common approaches to dealing with endogeneity include  quasi-experimental studies, instrumental variables regression (covered thoroughly in any econometrics text), and  propensity score matching.  
A: Knowledge of HIV transmission mechanisms, education, having friends with known positive HIV status, amount of contact with medical doctors for non-HIV related reasons, type of health insurance, sexual history/practices, drug history, income, sex, trust of medical profession, beliefs about friends getting tested, race.  You want variables which predict receiving the treatment (knowledge of HIV status), in an ideal world you could come up with some exogenous variables.  You also might think about multiple measures of a person's knowledge of their HIV status.  You could ask them to estimate the probability they have HIV.
