Hello everyone,
I have a quick (hopefully easy) question. When I use the -mean- command in Stata, it produces confidence intervals that do not match my results when I calculate these manually. Below is an example. I will use the auto.dta file in Stata so my results can be replicated.
I will use the variable "price," and using the -mean- command, I calculate 99% confidence intervals. The results are, N = 74, Mean = 6165.257, Std. Err. = 342.8719, Lower = 5258.405, Upper = 7072.108
To calculate this manually, I save the results of the mean and the std. err. as macros that I call "mean" and "std_err":
Stata calculates the standard error of the mean as the square root of the variance (pg.6, https://www.stata.com/manuals13/rmean.pdf). Thus, I use the saved variance from the -mean- command stored in vector V.
Now that I have the mean and std. err. saved as precise values from the command, I use the confidence interval calculation: mean +/- (t-ratio * standard error). I looked up the t-ratio for 74 degrees of freedom, and found 2.644. I save the results in global macros called "lower_ci" and "upper_ci" for the lower and upper bounds.
As my manual results show, I get a lower CI of 5258.7034, but this is different from the lower CI reported using the -mean- command, which is 5258.405. Likewise, my manual result for the upper CI is 7071.8101, but the one reported using -mean- is 7072.108. The results are close, but not exact. Does anyone know why this is? Additionally, does anyone know how I can use my manual method to get exact results to match the -mean- command in Stata?
Thanks!
I have a quick (hopefully easy) question. When I use the -mean- command in Stata, it produces confidence intervals that do not match my results when I calculate these manually. Below is an example. I will use the auto.dta file in Stata so my results can be replicated.
Code:
sysuse auto.dta
Code:
mean price, level(99)
Code:
matrix list e(b) mat b = e(b) global mean = b[1,1] dis $mean
Code:
matrix list e(V) mat V = e(V) global variance = V[1,1] global std_err = sqrt($variance) dis $std_err
Code:
global lower_ci = $mean - (2.644 * $std_err) dis $lower_ci global upper_ci = $mean + (2.644 * $std_err) dis $upper_ci
Thanks!
Comment