I have a tedious task, that I would like to outsource to R. I thought about a loop, that does the same for every wave ( "99" to "16"). Basically, whenever there is a 99 in the code below, I would like to adapt this for every wave.
I am used to STATA, where I would simply to this with replacing 99 with `wave' and use a foreach loop. Is there a simple way to do this in R? How can I reference a string in a loop?
Otherwise it might just be a "copy-paste"-task :-) Thanks a lot for your help!
`wave <- ("99", "00", "01", "02", "03", "04")`
names(m99) <- gsub("(^x99)|(^h99)|(^i99)|(^weih99)", "", names(m99))
names(m99) <- gsub("99$", "", names(m99))
names(m99) <- paste(names(m99), "h", sep="_")
m99$idhous <- m99$idhous_h
p99 <- list_files_p[[1]]
names(p99)
names(p99) <- gsub("(^p99)|(^i99)|(^weip99)","", names(p99))
names(list_files_p[[1]]) <- gsub("99$","", names(list_files_p[[1]]))
p99[,grep("^x",names(p99))] <- NULL
names(p99) <- paste(names(p99), "p", sep="_")
names(p99)
sort(table(names(p99)))
p99$idhous <- p99$idhous_p
pm99 <- left_join(p99, m99, by="idhous")