Dereje Fentie
2013-Nov-11 17:11 UTC
[R] Generating bootstrap samples from a panel data frame
With a data frame (call it *d*) composed of 2000 individuals and *n*observations for each individual (thus *2000n* observations in total), I would like to generate *k* bootstrap samples with replacement from *d*. Amongst other variables, *d* has a numeric variable *id* taking on identical value for observations belonging to the same individual. Taking into consideration the panel nature of the data, I want to generate many bootstrap samples with replacement and store each bootstrap sample data frame for further use. Sampling (or selection into the bootstrap sample) shall be based on individuals (on unique values of *id*) such that if an individual is in a particular bootstrap sample, so will all observations belonging to that individual. How can I do this in r? [[alternative HTML version deleted]]
Dereje Fentie
2013-Nov-14 15:52 UTC
[R] Generating bootstrap samples from a panel data frame
With a sample data frame: d = data.frame(id = rep(c(1,2,3,4),5), x = round(rexp(20), digits=2), y round(runif(20), digits=2)) I would like to generate 100 bootstrap data with replacement and save each bootstrap data as b1, b2, ..., b100. I attempted the sample function but could not make it work On Mon, Nov 11, 2013 at 6:11 PM, Dereje Fentie <derex.fen@gmail.com> wrote:> > With a data frame (call it *d*) composed of 2000 individuals and *n*observations for each individual (thus > *2000n* observations in total), I would like to generate *k* bootstrap > samples with replacement from *d*. Amongst other variables, *d* has a > numeric variable *id* taking on identical value for observations > belonging to the same individual. > > Taking into consideration the panel nature of the data, I want to generate > many bootstrap samples with replacement and store each bootstrap sample > data frame for further use. Sampling (or selection into the bootstrap > sample) shall be based on individuals (on unique values of *id*) such > that if an individual is in a particular bootstrap sample, so will all > observations belonging to that individual. > > How can I do this in r? >[[alternative HTML version deleted]]