Causal inference when individuals are observed at multiple points in time I am trying to estimate the causal effect of a treatment on an outcome. I would like to consider one control variable and a time dimension (week). The sample looks as follows:
+------------+---------+---------+-----------+---------+---+
| individual |  week   | control | treatment | outcome |   |
+------------+---------+---------+-----------+---------+---+
|         1  |  201701 | a       |         1 |       0 |   |
|          1 |  201702 | a       |        0 |       0 |   |
|          1 |  201703 | b       |         0 |       0 |   |
|          1 |  201704 | b       |         1 |       1 |   |
|          2 |  201703 | d       |         0 |       0 |   |
|          2 | 201704  | d       |         1 |       0 |   |
|          2 | 201705  | e       |         1 |       1 |   |
|          3 | 201801  | a       |         1 |       1 |   |
+------------+---------+---------+-----------+---------+---+

As you can see, I observe the same individual multiple times for the same control and also multiple times across controls. Once the outcome is 1, the individual drops out. So, I do not observe all individuals all the time.
As I said, I would like to measure the effect of the treatment by control and by week and if the effect does not differ across controls or across weeks I would like to pool across the respective dimension.
I am somewhat puzzled about which individuals to consider in the test (and possibly also regarding what test to apply) since I am observing individuals at multiple points in time.


*

*I would like to check for instance if the effect differs across weeks. But then the same individual might show up in two different weeks. Does this matter, and if yes how should I deal with it? Should I (randomly) consider each individual only once? Is there a test to deal with this kind of scenario?

*Suppose I would like to pool across controls (i.e. not consider weeks separately). How would I best approach this issue then?
As of now, I used a chi2-test to find the effect by week-control.
 A: Given that your data has individuals who are observed over time until the occurrence of an event, this can be modelled as a survival-regression model.  I will assume that the weeks in this analysis are denoted by a time index $t \geqslant 0$ with the first week in the analysis being $t = 0$.
Since it is unspecified, I am going to assume that your treatment for each individual in each week was allocated randomly with some fixed probability.  Random allocation of your treatment variable severs the causal link between this variable and any confounding factors that affect the outcome event.  This allows predictive differences from the treatment variable to be interpreted as causal effects of that variable.  (Since you have not offered any further detail, I will assume that this has been done in a way that allows legitimate causal inferences.)
EDIT: One more important point.  You say in your question you are confused about which individuals to include in your analysis and which weeks, etc. (owing to the fact that different individuals appear for different numbers of weeks).  With regard to this issue, it is generally not okay to ignore parts of the data that are inconvenient (in statistical parlance they are often 'non-ignorable').  You should include all your data and select an appropriate model that can take account of all of it.

For each individual $i$ we let $S_i$ be the random time at which the outcome occurs (the individual is not observed after that).  At each time $t$ this individual has a categorical control variable $x_{i,t}$ and a binary treatment variable $y_{i,t}$.  Based on these variables, we define the hazard-rate parameters:
$$\lambda_t (x_t, y_t) \equiv \mathbb{P}(S = t | S \geqslant t, x_t, y_t).$$
Hence, given a series of control variables and treatment variables, we have:
$$\mathbb{P}(S_i = s | \boldsymbol{x}_i, \boldsymbol{y}_i) = \lambda_s(x_{i,s}, y_{i,s}) \prod_{t=0}^{s-1} (1 - \lambda_t(x_{i,t}, y_{i,t})).$$
Your data-set consists of a set of observed survival times $\boldsymbol{s} = (s_1, ..., s_n)$ with corresponding control variables $\boldsymbol{x}$ and treatment variables $\boldsymbol{y}$ for each individual over each time period where the individual was observed.  Assuming that individuals are exchangeable and multiplying the individual sampling probabilities over all individuals yields the overall sampling probability:
$$\mathbb{P}(\boldsymbol{S} = \boldsymbol{s} | \boldsymbol{x}, \boldsymbol{y}) = 
\prod_{i=1}^n \lambda_s(x_{i,s}, y_{i,s}) \prod_{t=0}^{s-1} (1 - \lambda_t(x_{i,t}, y_{i,t})).$$
The corresponding log-likelihood function is:
$$l_{\boldsymbol{s} , \boldsymbol{x}, \boldsymbol{y}} (\boldsymbol{\lambda}) = 
\sum_{i=1}^n \ln \lambda_s(x_{i,s}, y_{i,s}) \sum_{t=0}^{s-1} \ln (1 - \lambda_t(x_{i,t}, y_{i,t})).$$
This model is presented at a high level of generality, where the hazard rates in each time period are allowed to vary freely.  The model can be tightened with further restrictions if you are willing to assume some correspondence of hazard rates over time.  If you want to test for independence of hazard rate over time then you would test against a simpler version.  This simpler version would assume that hazard rates do not depend on time (but still depend on the control and treatment in each period), which gives the log-likelihood:
$$l_{\boldsymbol{s} , \boldsymbol{x}, \boldsymbol{y}} (\boldsymbol{\lambda}) = 
\sum_{i=1}^n \ln \lambda(x_{i,s}, y_{i,s}) \sum_{t=0}^{s-1} \ln (1 - \lambda(x_{i,t}, y_{i,t})).$$
In this latter model, the unknown parameter matrix is $\boldsymbol{\lambda} = [\lambda (x,y) | x \in \mathscr{X}, y = 0, 1 ]$.  This version of the model allows reasonable estimates of the parameters to be made with much less data than the more generalised model.
Your data should allow you to estimate the hazard rate parameters for all observed values of the control and treatment variables.  This can be done using standard maximum-likelihood estimation (MLE) or using Bayesian methods.  Assuming you have a sufficient amount of data, this should lead you to be able to obtain parameters estimates for the hazard rates in your model, from whic you can then make causal inferences.

Causal inference: The true causal effect of applying the treatment (interpreted as an increase in the probability of the outcome occurring) with control variable $x$ is:
$$\phi (x) \equiv \lambda (x, y = 1) - \lambda (x, y = 0).$$
You can estimate this using the corresponding parameter estimates:
$$\hat{\phi} (x) \equiv \hat{\lambda} (x, y = 1) - \hat{\lambda} (x, y = 0).$$
If you have a large amount of data (i.e., many individuals, relative to the number of controls and observed times) then you should be able to get estimates of all the hazard rates over every control and treatment combination, at least for a reasonable number of times in the model.

Hopefully this gives you somewhere to start with your analysis.  A simple model with equal hazard rates over time might do it, but you will need to check this against more generalised models that allow for variation over time.  If your data is simple and has the "memoryless" property then it should be fairly simple.  Otherwise it might be a bit trickier.
