Calculating Beta and Confidence interval based on the group means and CI Based on an analysis we have done, we have means and CI for the means of our outcome variable for people who responded Yes or No to certain risk factors.
The data is thus structured as such:
            No       Yes
Mean        3.70      3.07
CI lower    3.51      2.62
CI upper    3.95      3.82


My question here is, when calculating the beta for this having answered yes to this risk factor, I must also use the CI for the people who answered NO in my calculation to contrast with the CI from Yes to create my beta's CI correct?
Could someone confirm that this is the appropriate way of calculating this? Thank you in advance.
 A: Under the hypothesis of a simple regression, the computation for the CI of the regression parameter seems incorrect. Below is a reproducible R code to compare the CI computed using the regression and the one computed as proposed in the question. I considered a confidence level of $0.95$ and symmetric intervals.
set.seed(42)
nsamp = 100
p = 0.5 #probability of x being yes
sigma2 = 1
alpha = 0.05 # 1 - confidence level
### Data
x = rbinom(nsamp, 1, p) # 1 means yes
y = 4 + 1*x + rnorm(nsamp, 0 , sigma2)

y_no = y[x == 0]
nsamp_no = length(y_no)
y_yes = y[x == 1]
nsamp_yes = length(y_yes)
### Fit
lm_y = lm("y~x", data.frame(x = x , y = y))

### CI computation
# CI for beta_yes on the regression model
CI_beta_correct = confint(lm_y, "x", 1-alpha)

# CI computation as asked on the question
mu_no = mean(y_no)
sigma_no = sd(y_no)
mu_yes = mean(y_yes)
sigma_yes = sd(y_yes)
q_a = qnorm(1-(alpha/2))
CI_mu_no = mu_no + c(-q_a*(sigma_no/nsamp_no), q_a*(sigma_no/nsamp_no))
CI_mu_yes = mu_yes + c(-q_a*(sigma_yes/nsamp_yes), q_a*(sigma_yes/nsamp_yes))

### CI comparison
CI_beta_test = c(CI_mu_yes[1] - CI_mu_no[2], CI_mu_yes[2] - CI_mu_no[1])
CI_beta_test
CI_beta_correct

In the exampled, the interval is narrower than the true interval.
To correctly compute the CI in R, fit a linear model and use the confint function, as examplified in the code.
Why it is incorrect
Consider the regression model
$$Y \sim \mathcal{N}(\beta_0 + \beta_1I_{new}(X), \sigma^2) \quad.$$
Your aim is to create a symmetric CI for $\beta_1$ with confidence $1 - \alpha$. Let $\hat{\mu_0}$ and $\hat{\mu_1}$ be the mean estimated for y when x is "no" and when x is "yes", respectively. Common regression computations show that $\hat{\beta_1} = \hat{\mu_1} - \hat{\mu_0}$ and
$$\hat{\beta_1} \sim \mathcal{N}\left(\beta_1, \frac{n\sigma^2}{n_0n_1}\right) \quad,$$
Where n is the sample size, $n_0$ the number of "no" and $n_1$ the number of "yes".
Letting $\hat{\sigma^2}$ be the regression estimator for the variance, the CI is
$$CI(\beta_1; 1 - \alpha) = \left[\hat{\beta_1} - z_{1-\alpha/2}\frac{\sqrt{n}\hat{\sigma}}{\sqrt{n_0n_1}}, \hat{\beta_1} + z_{1-\alpha/2}\frac{\sqrt{n}\hat{\sigma}}{\sqrt{n_0n_1}}\right] \quad.$$
Letting $\hat{\sigma_0^2}$ be the variance of y when x is "no", the CI for the mean is
$$CI(\mu_{0}; 1 - \alpha) = \left[\hat{\mu_0} - z_{1-\alpha/2}\frac{\hat{\sigma_0}}{\sqrt{n_0}}, \hat{\mu_0} + z_{1-\alpha/2}\frac{\hat{\sigma_{0}}}{\sqrt{n_0}}\right] \quad.$$
The same result holds for the "yes", judt swap the indices from 0 to 1. Finally, the CI  you proposed, obtaines by subtracting the opposed extremes, is
$$\left[\hat{\beta_1} - z_{1-\alpha/2}\left(\frac{\hat{\sigma_1}}{\sqrt{n_1}}+\frac{\hat{\sigma_0}}{\sqrt{n_0}}\right), \hat{\beta_1} + z_{1-\alpha/2}\left(\frac{\hat{\sigma_1}}{\sqrt{n_1}}+\frac{\hat{\sigma_{0}}}{\sqrt{n_0}}\right)\right] \quad.$$
The interval is centered on the correct estimate, however the variation term is off. This is simply because
$$\hat{\sigma^2} = \left(\frac{n_1}{n}\hat{\sigma_{1}^2}+\frac{n_0}{n}\hat{\sigma_{0}^2}\right) \quad.$$
This equation shows that the total variance is a convex combination of the  groups variances. However, the total standard deviation is not a convex combination of groups standard deviations, which is what appears on the variation term of your CI.
