If I understand correctly, the following should do it: lag.max2 <- function(object, n = 12){ matris <- matrix(NA, nrow = n) for(i in 1:n){ matris[i] <- ur.df(object, lags = i, type = "trend")@testreg$coefficients[i+3,4] if(matris[i]<0.1) break } # output c('lag' = i, 'p' = matris[i]) } a2 <- lag.max2(a1) a2 # lag p # 1.00000000 0.09613726
HTH, Jorge On Sat, Dec 11, 2010 at 3:17 PM, Serdar Akin <> wrote: > Hi > > I'm trying to utilize the break command for breaking the loop when the > p-value is less than 10 per cent using the urca package. But it does not > break the loop, anyone that can help me? > > library(urca) > set.seed(1) > a1 <- runif(100) > lag.max <- function(object, n = 12){ > matris <- matrix(NA, nrow = n) > for(i in 1:n) { > matris[i] <- ur.df(object, lags = i, > type = "trend")@testreg$coefficients[i+3,4] > if (i < 0.1) {break(i)} > } > list(matris = round(matris, 3)) > } > a2 <- lag.max(a1) > > /With regards > Serdar > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.