Hi all,
Trying to use bootstrapping to calculate a confidence interval of the ratio of two different predicted values by a third variable. The data below isn't exactly like my data, but it comes close enough to be practical in this instance, I think. In this data, I have observations at the person level. I am trying to calculate the confidence interval for the ratio of the predicted_weight/predicted height by race. So, ideally, for each race I would have a variable demonstrating the lower and upper bound of the confidence interval associated with the actual ratio of the average of the predicted_height/ average of the predicted_weight. I would be fine collapsing the data by race at some point, but I would prefer to have the confidence interval listed at the observation level as well (just denoting for each patient the confidence interval associated with the race.
When I run the program itself, I get the actual averaged predicted_height / averaged-Predicted weight, as I would hope. However, when I run the bootstrapping command. I get an "Evaluation to missing" error. I am not 100% sure why, except that in the course of the bootstrapping some values are generated as missing because there are no samples within the specific race?
As always, thanks in advance!
Using Stata 18.0 on OS14.0
Trying to use bootstrapping to calculate a confidence interval of the ratio of two different predicted values by a third variable. The data below isn't exactly like my data, but it comes close enough to be practical in this instance, I think. In this data, I have observations at the person level. I am trying to calculate the confidence interval for the ratio of the predicted_weight/predicted height by race. So, ideally, for each race I would have a variable demonstrating the lower and upper bound of the confidence interval associated with the actual ratio of the average of the predicted_height/ average of the predicted_weight. I would be fine collapsing the data by race at some point, but I would prefer to have the confidence interval listed at the observation level as well (just denoting for each patient the confidence interval associated with the race.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(race predicted_weight predicted_height) 1 67 180 1 65 175 1 63 170 2 62 173 2 52 169 2 51 180 2 77 155 3 63 170 3 29 190 3 18 200 end
Code:
program define calc_ratio * Assuming the original dataset is loaded and the program is called in the context of bootstrap egen mean_predicted_weight = mean(predicted_weight), by(race) egen mean_predicted_height = mean(predicted_height), by(race) gen ratio = mean_predicted_height / mean_predicted_weight end * Run the bootstrap command bootstrap r(ratio), reps(1000) seed(12345): calc_ratio * Calculate the confidence intervals gen lower_ci = r(ratio) - invttail(r(df_r), 0.025)*r(se) gen upper_ci = r(ratio) + invttail(r(df_r), 0.025)*r(se)
As always, thanks in advance!
Using Stata 18.0 on OS14.0
Comment