I am new to stan and I want to use the Matt trick on a positive parameter beta. How can I do the Matt trick on the log scale? Is it as simple as this:
parameters { vector[K] beta_raw;
…
transformed parameters {
vector[K] beta;
// implies: beta ~ lognormal(mu_beta, sigma_beta)
beta = exp(mu_beta + sigma_beta * beta_raw);

model { beta_raw ~ normal(0, 1);
…

Additionally, if I observe a slower performance when I use the Matt trick does this mean I am doing something wrong with it?

When comparing performance of different parameterisations, remember to use the effective samples obtained per second (not merely the total sampling time). A model that samples a little bit more slowly but gathers many more samples is superior.

If I recall correctly, the Matt trick ( more recently referred to as “non-centered parameterisation”) should yield superior performance when there is little data compared to the number of parameters, but if the reverse is true, the centered parameterisation will have better performance. But I’m not sure if the log transform affects the geometry of this result.

After we learned it’s conventional name, we switched to calling it the “non-centered parameterization”.

And yes, your version’s right for lognormal variates. You only need to define beta as a transformed parameter (rather than a local variable in the model block) if you want to save it.