Hello, everybody!

I have an array of categorical answers y (in Y), where each column is associated with a time t (in T) and each row with an individual i (in N).

For each time t , I have the design matrix X and an auxiliar quantity n (that is an index for my padding values process, solved in Padding values in response arrays with different sizes)

```
data{
int<lower = 1> N; // Sample size
int<lower = 1> K; // Categories
int<lower = 1> D; // Covariates dimension
int<lower = 1> T; // Time dimension
int n[T]; // `Real` sample size
matrix[N, D] X[T]; // Covariates
int Y[N, T] ; // Answers
}
```

As I’m modelling a transition probability matrix for a markov process, my aim is to estimate the vectors of probabilities for two states. In other words, two rows of that matrix.

To do that, I assume that the answers (states at time t) follow a multinomial distribution and use the categorical_logit_lpmf function to estimate the parameters (betas) associated with the covariates.

```
parameters{
matrix [D, K-1] beta3_aux;
matrix [D, K-1] beta4_aux;
}
transformed parameters{
matrix [D, K] beta3;
matrix [D, K] beta4;
for(d in 1:D){
beta3[d] = append_col(-sum(beta3_aux[d]), beta3_aux[d]);
beta4[d] = append_col(-sum(beta4_aux[d]), beta4_aux[d]);
}
}
```

So, as I have to estimate two different vectors of parameters using the same vector of answers at time t, I have to take into account the state to not use informations worng.

My difficult is being to create a conditional statment that works fine in Stan.

I tried in that whay (the indexes are correct, I guess).

```
model{
for(t in 2:T){
for(i in 1:n[t]){
if(Y[i,t] == 3) {
target += categorical_logit_lpmf(Y[i,t] | (X[t-1,i,]*beta3)');
}
else {
target += categorical_logit_lpmf(Y[i,t] | (X[t-1,i,]*beta4)');
}
}
}
}
```

but it stops at the first interation

```
Chain 1: Iteration: 1 / 500 [ 0%] (Warmup)
```

In summary, I need some help to review and, maybe, optmize the code, because it is not working in that way :/

I was using categorical_logit_glm_lpmf function when I was not separating observations according to states and it was really good. I wish I could continue to use that, but I don’t think it is possible to use conditionals on that.

Thanks a lot!