How to derive beta from my regression line? I’m struggling to understand the formula for deriving the beta coefficient in a univariate regression model.
Say Y = 1 + 2x
Here beta would be 2.
The formula say
$$
b = \dfrac{\sum xy}
{\sum x^2}
$$
But taking values of x=1,2,3 and y=3,5,7 and then trying to work out beta, I do not obtain 2. I obtain 34/14?

Your equation is true in the special case where the mean of $x$ is $0$ and the mean of $y$ is $0$, such as when you center your variables. In general, you want the following equation.
$$
\beta = \dfrac{
\text{cov}(X, Y)
}{
\text{var}(X)
}
=
\dfrac{\sum\big(
x_i - \bar x
\big)
\big(
y_i - \bar y
\big)}{\sum\big(
x_i - \bar x
\big)^2}
$$
When $\bar x=0$ and $\bar y=0$, we get the equation you gave, but your $\bar x=2$ and $\bar y=5$.
This can be verified in software like R.
x <- c(1, 2, 3)
y <- c(3, 5, 7)
cov(x, y)/var(x)
sum((x - mean(x))*(y - mean(y)))/sum((x - mean(x))^2)

Both calculations give me $2$.
