I’m trying to model a Generalised Least Squares panel data model with a diagonal variance-covariance matrix, i.e. y_i|X_i,\beta,\Sigma \sim N(X_i\beta,\Sigma),\ \Sigma=diag(\sigma^2_1,\dots,\sigma^2_T). I’ve been able to model a Panel Data model with a common variance, i.e. y_i|X_i,\beta,\sigma^2_\varepsilon\sim N(X_i\beta,\sigma^2_\varepsilon I_T), but I fail with multiple components. I have, however, been able to write the code for an arbitrary \Sigma, but that code failed due to memory limitations (N=2376) and I know that the matrix is diagonal anyway. Could anyone give a hint on how to make this code work for multiple variance components?

```
data {
int<lower=0> N; \\ Number of cross-sectional units
int<lower=0> K; \\ Number of regressors
real bval[N]; \\ y-value
real btreat[N]; \\ Regressor 1
real bcountrd[N]; \\ Regressor 2
}
parameters {
real beta[K];
real sigma[N];
}
transformed parameters {
real mu[N];
for (i in 1:N) {
mu[i] = beta[1]+beta[2]*btreat[i]+beta[3]*bcountrd[i];
}
}
model {
// Likelihood
bval ~ normal(mu,sigma);
}
```

Thanks in advance.