Manually calculating the tstat in r I'm getting wildly different answers when I calculate the t-statistic manually vs the t-stat shown in the regression summary. Any ideas how to fix it?
x1 = runif(4000, min = 0, max = 1)
x2 = runif(4000, min = 0, max = 1)

y <- 1*x1 - 2*x2 + rnorm(4000)

X = cbind(x1,x2)

# Manually find OLS estimators
estimators <- solve(t(X)%*%X)%*%t(X)%*%y
> estimators
        [,1]
x1  1.020039
x2 -2.012627

# Manually find tstat for x2
> -2.012627 / (sd(x2)/sqrt(length(x2)))
[1] -441.7463


# tstat from regression
reg1 = lm(y ~ ., data = yx)
summary(reg1)

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.01027    0.04225  -0.243    0.808    
x1           1.02882    0.05516  18.653   <2e-16 ***
x2          -2.00394    0.05523 -36.284   <2e-16 ***




The t-statistic you're using is the definition of the t-statistic for a difference in means between 2 groups, which is different. The R software is giving the correct coefficient; the t-statistic is defined as the estimate divided by the standard error. In this case, the standard error is not equal to sd(x2) / sqrt(length(x2)).
