Help replicating example from Imbens and Rubin's Causal Inference book

I think it’s the same issue as discussed in this thread.

The typical treatment effect calculation assumes that the residual will be the same for Y_0 and Y_1. The way you set up the generated quantities allows for different residuals. With the normal distribution this will only have an effect on the uncertainty in Tau but with the more complex distribution it can have an effect on the expectation of Tau as well. I think in pseudo code you want to calculate the Tau as follows.

if (W[i] == 1){
  Y_1[i] = Y_obs[i];
  // work in expectations for precision  
  Y1is0 = inv_logit(X[i]) * gamma_1);
  Resid = Y_obs[i] - Y1is0 * exp(X[i] * beta_1)
  Y0is0 = inv_logit(X[i]) * gamma_0);
  Y_0[i] = Y0is0 * exp(X[i] * beta_0) + Resid
}

If I am correct, that means that you can actually calculated tau directly as

Y1is0 = inv_logit(X[i]) * gamma_1)
Y0is0 = inv_logit(X[i]) * gamma_0)
tau_individual[i] = Y1is0 * exp(X[i] * beta_1) - Y0is0 * exp(X[i] * beta_0)