for loop and test statistic

library(tseries)
set.seed(123)
result <- NULL
for (i in 1:1000) {
  n_entities <- 5
  n_years <- 10
  id <- rep(1:n_entities, each = n_years)
  year <- rep(2000:2009, times = n_entities)
  value <- cumsum(rnorm(n_entities * n_years))
  data <- data.frame(id = id, Year = year, Value = value)
  result [i] = adf.test(data$Value)$statistic
}

I want to generate a panel data sets with 5 units and 10 observations in r and get the test statistics. However, my problem here is to do this process 1000 times. For each id I need to restart the cumsum argument again for randomness. I want to create 1000 random data sets by providing randomness in each unit separately and apply adf.test to them 1000 times. Does anyone have any ideas?
I tried to edit it with different codes, but I realized that the data set does not get the cumulative sum for each unit (n_entities) again. I need to generate a cumulative random data set for each unit in turn, rather than setting the size and filling it with data.

I think its

 value <- unlist(lapply(1:n_entities,\(x)cumsum(rnorm(n_years))))

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.