################################################################################ ## Function: x0 <- rand.x (p, x) ## Inputs: p >> 0 is a (k by t) matrix of prices, x >= 0 is a (k by t) matrix ## of consumption bundles, k >= 2 is the number of goods, t >= 1 is the number ## of observations ## Outputs: x0 >= 0 is a matrix of uniformly random consumption bundles ## Libraries: gtools ## Description: returns a matrix of consumption bundles chosen uniformly ## randomly from the budgets corresponding to a given data set of prices and ## consumption bundles ################################################################################ rand.x <- function (p, x) { # number of goods k <- dim (p)[1] # number of observations t <- dim (p)[2] # generate uniformly random budget shares w0 <- t (rdirichlet (t, rep (1, k))) # generate uniformly random consumption bundles p.x <- apply (p * x, 2, sum) p.x <- matrix (p.x, k, t, byrow = TRUE) x0 <- w0 * p.x / p # clean and return result result <- x0 remove (k, p, p.x, t, x, x0, w0) return (result) }