Suppose I have a regression problem y_{i} \sim N(\alpha + x_{i}\beta, \sigma), where for each sample i I observe some continuous y_{i} and x_{i}. If now each sample i also belongs to a group kk_{i} and I expect \beta to vary by group, am I allowed to write the model like this?

```
data {
int N;
real y[N];
real x[N];
int K;
int<lower=1, upper=K> kk[K];
}
parameters {
real alpha;
real<lower=0> sigma;
vector[K] beta;
}
model {
for (i in 1:N)
y[i] ~ normal(alpha + beta[kk[i]] * x[i], sigma);
}
```

What confuses me is that most people seem to use a K-1 dimensional design matrix when representing a K dimensional categorical variable and here I have a K-dimensional vector \beta plus the intercept. I’ve tried it with some fake data and it seems to recover the original values, so is there anything obvious I’m missing here (aside from things like computational speed)?