So, my guess is that you want something like this:
for (t in 2:T) {
sum_xp <- 0
for (h in 0:(M-1)) {sum_x_p <- sum_xp + x**h * p[t-h]}
y[t] <- b[t] + sum_xp
}
note that the assignment of y[t] is outside of the for-loop.
Also, it would help to understand what the variables x,y,p etc. look like, but I assume I guessed correctly.
One more thing about Speed:
The funny thing in R is that if you want fast code, you want to avoid big for-loops and instead vectorize your code.
There is all kinds of "apply"-shenanegans in R which can make vectorization easier, but it needs some abstract thinking to implement. As a reference for all kinds of apply-magic I recommend the Advanced R Handbook.
If speed is not so much of an issue, go ahead with the traditional for-loops ;-)