I am estimating a linear model, where I want to estimate the threshold value for an indicator variable together with the normal selection coefficients.

I have the following model in Stan:

```
data {
int N; // no observastions
// Covariates
real x1[N];
real x2[N];
// Count outcome
real y[N];
}
parameters {
real betas[3];
real <lower=0> gamma;
real <lower=0> sigma;
}
model {
real mu[N];
// Likelihood
for (i in 1:N) {
mu[i] = betas[1] + betas[2] * x1[i] + betas[3] * (x2[i] < gamma);
}
y ~ normal(mu, sigma);
}
```

Where `gamma`

is the the threshold to classify `x2`

into 0 and 1. I have two questions:

- Is this the right way to specify my problem in Stan? If I run the model on simulated data, I can recover the correct parameter values.
- Are there any tricks I could use to speed up computation?