I can easily simulate a data set where the regression residuals are iid with 0 mean and constant variance.
set.seed(123)
x = rnorm(100)
y = 50 + 25* x + rnorm(100)
df = data.frame(y=y, x=x)
The data assumes that the population regression equation is $$y = \beta_0 + \beta_1X_1 + \epsilon$$
And $\epsilon$ is white noise (0 mean, constant variance).
I want to simulate a data set where the residuals are correlated and assume the following population regression equation
$$
\begin{aligned}
y_t &= \beta_0 + \beta_1X_{1,t} + \epsilon_t, \\
\epsilon_t &= \rho\epsilon_{t-1} + v_t, \\
\end{aligned}
$$
and $v_t$ is white noise (0 mean, constant variance).
How would I create this data frame in R?
Best Answer
Found it.