I have successfully translated this RStan case study into cmdStan: https://mc-stan.org/users/documentation/case-studies/golf.html

I am now trying to do the same with this one: https://mc-stan.org/users/documentation/case-studies/model-based_causal_inference_for_RCT.html

Unfortunately I get this error when I run the executable:

```
Exception: variable does not exist; processing stage=data initialization; variable name=y; base type=double (in 'examples/Model-based-Inference-for-Causal-Effects-in-Completely-Randomized-Experiments/experiments.stan', line 3, column 2 to column 14)
```

What I causing this ?

Here is my code:

experiments.data.R (1.3 KB)

```
data {
int<lower=0> N; // sample size
vector[N] y; // observed outcome
vector[N] w; // treatment assigned
real<lower=-1,upper=1> rho; // assumed correlation between the potential outcomes
}
parameters {
real alpha; // intercept
real tau; // super-population average treatment effect
real<lower=0> sigma_c; // residual SD for the control
real<lower=0> sigma_t; // residual SD for the treated
}
model {
// PRIORS
alpha ~ normal(0, 5);
tau ~ normal(0, 5);
sigma_c ~ normal(0, 5);
sigma_t ~ normal(0, 5);
// LIKELIHOOD
y ~ normal(alpha + tau*w, sigma_t*w + sigma_c*(1 - w));
}
generated quantities{
real tau_fs; // finite-sample average treatment effect
real y0[N]; // potential outcome if W = 0
real y1[N]; // potential outcome if W = 1
real tau_unit[N]; // unit-level treatment effect
for(n in 1:N){
real mu_c = alpha;
real mu_t = alpha + tau;
if(w[n] == 1){
y0[n] = normal_rng(mu_c + rho*(sigma_c/sigma_t)*(y[n] - mu_t), sigma_c*sqrt(1 - rho^2));
y1[n] = y[n];
}else{
y0[n] = y[n];
y1[n] = normal_rng(mu_t + rho*(sigma_t/sigma_c)*(y[n] - mu_c), sigma_t*sqrt(1 - rho^2));
}
tau_unit[n] = y1[n] - y0[n];
}
tau_fs = mean(tau_unit);
}
```