My first guess is that your loop is over the wrong item.
Here is your code repeated, with spacing around the arrows
and tilde for improved legibility.
regr <- lm(withrand ~ when)
b1 <- regr$coefficients[2]
se.b1 <- summary(regr)$coefficients[2,2]
Your last two lines can be replaced by the single line
coef(summary(regr))[2,1:2]
Assuming you have two matrices, and want to regress respective
columns of y and x,
y <- matrix(rnorm(50), 10, 5)
x <- matrix(rnorm(50), 10, 5)
b.se <- matrix(0, 2, 5,
dimnames=list(1:2, c("Value", "Std. Error")))
for (i in 1:5)
bs.e[i,] <- coef(summary(lm(y[,i] ~ x[,i])))[2, 1:2]
b.se
The results are stored in a matrix so you can index into them.
|