Title: | Performs a BLP Demand Estimation |
---|---|
Description: | Provides the estimation algorithm to perform the demand estimation described in Berry, Levinsohn and Pakes (1995) <DOI:10.2307/2171802> . The routine uses analytic gradients and offers a large number of implemented integration methods and optimization routines. |
Authors: | Daniel Brunner (aut), Constantin Weiser (ctr), Andre Romahn (ctr) |
Maintainer: | Daniel Brunner <[email protected]> |
License: | GPL-3 |
Version: | 0.3.4 |
Built: | 2024-11-19 06:30:46 UTC |
Source: | CRAN |
Prepares data and parameters related to the BLP algorithm for estimation.
BLP_data( model, market_identifier, product_identifier, par_delta, group_structure = NULL, additional_variables = NULL, productData, demographic_draws, integration_accuracy, integration_method, integration_draws, integration_weights, integration_seed, blp_inner_tol = 1e-09, blp_inner_maxit = 10000 )
BLP_data( model, market_identifier, product_identifier, par_delta, group_structure = NULL, additional_variables = NULL, productData, demographic_draws, integration_accuracy, integration_method, integration_draws, integration_weights, integration_seed, blp_inner_tol = 1e-09, blp_inner_maxit = 10000 )
model |
the model to be estimated in R's formula syntax, |
market_identifier |
character specifying the market identifier (variable name must be included in |
product_identifier |
character specifying the product identifier (variable name must be included in |
par_delta |
optional: numeric vector with values for the mean utility (variable name must be included in |
group_structure |
optional: character specifying a group structure for clustered standard erros (variable name must be included in |
additional_variables |
optional: character vector specifying variables you want to keep for later analysis (variable names must be included in |
productData |
data.frame with product characteristics, |
demographic_draws |
optional: list with demographic draws for each market to consider observed heterogeneity (see details), |
integration_accuracy |
integer specifying integration accuracy, |
integration_method |
character specifying integration method, |
integration_draws |
numeric matrix of manually provided integration draws (see details), |
integration_weights |
numeric vector of manually provided integration weights, |
integration_seed |
seed for the draws of Monte Carlo based integration, |
blp_inner_tol |
tolerance for the contraction mapping (default: 1e-9), |
blp_inner_maxit |
maximum iterations for the contraction mapping (default: 10000) |
For any form of user provided integration draws, i.e. integration_draws
(unobserved heterogeneity)
or demographic_draws
(observed heterogeneity), list entries must be named and contain the variable market_identifier
to allow market matching.
Each line in these list entries contains the draws for one market.
In case of unobserved heterogeneity, list names must match the random coefficients from the model formula.
The par_delta
argument provides the variable name for mean utilitys. For example, in the estimation algorithm these values are used as starting guesses in the contraction mapping.
Another example is the evaluation of the GMM, which is also based on the provided mean utilitys.
If you need to update par_delta
or any other variable in the data object, use update_BLP_data
.
Returns an object of class blp_data
.
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1)
Draws for observed heterogeneity in Nevo's cereal example.
demographicData_cereal
demographicData_cereal
Draws for observed heterogeneity for each demographic.
market identifier,
20 draws differing across markets.
https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/26803/SOF9FW&version=1.0
Calculates derivatives of all shares with respect to all mean utilities in a given market.
dstddelta_wrap(blp_data, par_theta2, market, printLevel = 1)
dstddelta_wrap(blp_data, par_theta2, market, printLevel = 1)
blp_data |
data object created by the function |
par_theta2 |
matrix with column and rownames providing a starting value for the optimization routine (see details), |
market |
character specifying the market in which derivatives are calculated, |
printLevel |
level of output information (default = 1) |
NA's in par_theta2
entries indicate the exclusion from estimation, i.e. the coefficient is assumed to be zero.
If only unobserved heterogeneity is used (no demographics), the column name of par_theta2
must be "unobs_sd".
With demographics the colnames must match the names of provided demographics (as in demographic_draws
) and "unobs_sd".
Row names of par_theta2
must match random coefficients as specified in model
. Constants must be named "(Intercept)".
Returns a numeric matrix with derivatives. Cell in row i and col j is the derivative of share i with respect to mean utility j.
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta2 <- matrix(c(0.5,2), nrow=2) rownames(theta2) <- c("x1","x2") colnames(theta2) <- "unobs_sd" derivatives2 <- dstddelta_wrap( blp_data=blp_data, par_theta2 = theta2, market = 2)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta2 <- matrix(c(0.5,2), nrow=2) rownames(theta2) <- c("x1","x2") colnames(theta2) <- "unobs_sd" derivatives2 <- dstddelta_wrap( blp_data=blp_data, par_theta2 = theta2, market = 2)
Calculates derivatives of all shares with respect to all non-linear parameters in a given market.
dstdtheta_wrap(blp_data, par_theta2, market, printLevel = 1)
dstdtheta_wrap(blp_data, par_theta2, market, printLevel = 1)
blp_data |
data object created by the function |
par_theta2 |
matrix with column and rownames providing a starting value for the optimization routine (see details), |
market |
character specifying the market in which derivatives are calculated, |
printLevel |
level of output information (default = 1) |
NA's in par_theta2
entries indicate the exclusion from estimation, i.e. the coefficient is assumed to be zero.
If only unobserved heterogeneity is used (no demographics), the column name of par_theta2
must be "unobs_sd".
With demographics the colnames must match the names of provided demographics (as in demographic_draws
) and "unobs_sd".
Row names of par_theta2
must match random coefficients as specified in model
. Constants must be named "(Intercept)".
Returns a numeric matrix with derivatives. Cell in row i and col j is the derivative of share i with respect to parameter j.
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta2 <- matrix(c(0.5,2), nrow=2) rownames(theta2) <- c("x1","x2") colnames(theta2) <- "unobs_sd" derivatives1 <- dstdtheta_wrap( blp_data=blp_data, par_theta2 = theta2, market = 2)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta2 <- matrix(c(0.5,2), nrow=2) rownames(theta2) <- c("x1","x2") colnames(theta2) <- "unobs_sd" derivatives1 <- dstdtheta_wrap( blp_data=blp_data, par_theta2 = theta2, market = 2)
Ownership matrix in BLP's car example.
dummies_cars
dummies_cars
Dummy variables.
1, if product in row j is produced by firm i, 0 otherwise
https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/26803/SOF9FW&version=1.0
Performs a BLP demand estimation.
estimateBLP( blp_data, par_theta2, solver_method = "BFGS", solver_maxit = 10000, solver_reltol = 1e-06, standardError = "heteroskedastic", extremumCheck = FALSE, printLevel = 2, ... )
estimateBLP( blp_data, par_theta2, solver_method = "BFGS", solver_maxit = 10000, solver_reltol = 1e-06, standardError = "heteroskedastic", extremumCheck = FALSE, printLevel = 2, ... )
blp_data |
data object created by the function |
par_theta2 |
matrix with column and rownames providing a starting value for the optimization routine (see details), |
solver_method |
character specifying the solver method in |
solver_maxit |
integer specifying maximum iterations for the optimization routine (default=10000), |
solver_reltol |
integer specifying tolerance for the optimization routine (default= 1e-6), |
standardError |
character specifying assumptions about the GMM residual (homoskedastic , heteroskedastic (default), or cluster) |
extremumCheck |
if |
printLevel |
level of output information ranges from 0 (no GMM results) to 4 (every norm in the contraction mapping) |
... |
additional arguments for |
NA's in par_theta2
entries indicate the exclusion from estimation, i.e. the coefficient is assumed to be zero.
If only unobserved heterogeneity is used (no demographics), the column name of par_theta2
must be "unobs_sd".
With demographics the colnames must match the names of provided demographics (as in demographic_draws
) and "unobs_sd".
Row names of par_theta2
must match random coefficients as specified in model
. Constants must be named "(Intercept)".
Returns an object of class "blp_est". This object contains, among others, all estimates for preference parameters and standard errors.
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" blp_est <- estimateBLP(blp_data =blp_data, par_theta2 = theta_guesses, extremumCheck = FALSE , printLevel = 1 ) summary(blp_est)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" blp_est <- estimateBLP(blp_data =blp_data, par_theta2 = theta_guesses, extremumCheck = FALSE , printLevel = 1 ) summary(blp_est)
Calculates elasticities for a given variable and market.
get_elasticities( blp_data, share_info, theta_lin, variable, products, market, printLevel = 1 )
get_elasticities( blp_data, share_info, theta_lin, variable, products, market, printLevel = 1 )
blp_data |
data object created by the function |
share_info |
object with individual and aggregated choice probabilities created by the function |
theta_lin |
linear parameter of the variable for which elasticities are calculated for, |
variable |
character specifying a variable for which elasticities are calculated for, |
products |
optional: character vector of specific products, |
market |
character specifying the market in which elasticities are calculated |
printLevel |
level of output information (default = 1) |
Returns a matrix with elasticities. Value in row j and col i for a variable x, gives the effect of a change in product i's characteristic x on the share of product j.
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" shareObj <- getShareInfo( blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 1) get_elasticities(blp_data=blp_data, share_info = shareObj , theta_lin = 1, variable = "price", products = c("4","20"), market = 1)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" shareObj <- getShareInfo( blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 1) get_elasticities(blp_data=blp_data, share_info = shareObj , theta_lin = 1, variable = "price", products = c("4","20"), market = 1)
Performs a contration mapping for a given set of non-linear parameters.
getDelta_wrap(blp_data, par_theta2, printLevel = 1)
getDelta_wrap(blp_data, par_theta2, printLevel = 1)
blp_data |
data object created by the function |
par_theta2 |
matrix with column and rownames providing a starting value for the optimization routine (see details), |
printLevel |
level of output information (default = 1) |
NA's in par_theta2
entries indicate the exclusion from estimation, i.e. the coefficient is assumed to be zero.
If only unobserved heterogeneity is used (no demographics), the column name of par_theta2
must be "unobs_sd".
With demographics the colnames must match the names of provided demographics (as in demographic_draws
) and "unobs_sd".
Row names of par_theta2
must match random coefficients as specified in model
. Constants must be named "(Intercept)".
Starting guesses for the contraction mapping are provided with BLP_data
.
Returns an object of class "blp_cm" with results from the contraction mapping.
delta
resulting vector of mean utilities after the contraction mapping
counter
inner iterations needed to convergence
sij
market share integral evaluations for each product (in rows) for the final mean utility
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" delta_eval <- getDelta_wrap( blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 4)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" delta_eval <- getDelta_wrap( blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 4)
Calculating the Jacobian for a given set of non-linear parameters and mean utilities.
getJacobian_wrap(blp_data, par_theta2, printLevel = 1)
getJacobian_wrap(blp_data, par_theta2, printLevel = 1)
blp_data |
data object created by the function |
par_theta2 |
matrix with column and rownames providing the evaluation point (see details), |
printLevel |
level of output information (default = 1) |
NA's in par_theta2
entries indicate the exclusion from estimation, i.e. the coefficient is assumed to be zero.
If only unobserved heterogeneity is used (no demographics), the column name of par_theta2
must be "unobs_sd".
With demographics the colnames must match the names of provided demographics (as in demographic_draws
) and "unobs_sd".
Row names of par_theta2
must match random coefficients as specified in model
. Constants must be named "(Intercept)".
Returns a matrix with the jacobian (products in rows, parameters in columns).
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" jacobian <- getJacobian_wrap(blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 2) head(jacobian)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" jacobian <- getJacobian_wrap(blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 2) head(jacobian)
Calculating the GMM objective for a given set of non-linear parameters.
gmm_obj_wrap(blp_data, par_theta2, printLevel = 2)
gmm_obj_wrap(blp_data, par_theta2, printLevel = 2)
blp_data |
data object created by the function |
par_theta2 |
matrix with column and rownames providing a starting value for the optimization routine (see details), |
printLevel |
level of output information ranges from 1 (no GMM results) to 4 (every norm in the contraction mapping) |
NA's in par_theta2
entries indicate the exclusion from estimation, i.e. the coefficient is assumed to be zero.
If only unobserved heterogeneity is used (no demographics), the column name of par_theta2
must be "unobs_sd".
With demographics the colnames must match the names of provided demographics (as in demographic_draws
) and "unobs_sd".
Row names of par_theta2
must match random coefficients as specified in model
. Constants must be named "(Intercept)".
Returns a list with results from the GMM evaluation.
local_min
GMM point evaluation
gradient
GMM derivative with respect to non-linear parameters
delta
result of the contraction mapping
xi
residuals of GMM evaluation
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" gmm <- gmm_obj_wrap( blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 2) gmm$local_min
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) theta_guesses <- matrix(c(0.5,2), nrow=2) rownames(theta_guesses) <- c("x1","x2") colnames(theta_guesses) <- "unobs_sd" gmm <- gmm_obj_wrap( blp_data=blp_data, par_theta2 = theta_guesses, printLevel = 2) gmm$local_min
Draws for unobserved heterogeneity in Nevo's cereal example.
originalDraws_cereal
originalDraws_cereal
Each list entry contains draws (unobserved heterogeneity) for a random coefficient.
market identifier,
20 draws differing across markets.
https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/26803/SOF9FW&version=1.0
Product data of BLP's car example.
productData_cars
productData_cars
A data frame with product data of 2217 cars in 20 markets.
car market share,
car price,
horsepower-weight ratio,
1, if car has air conditioning, 0 otherwise,
market identifier,
length times width of the car,
constant,
uniquely identifies a car,
uniquely identifies the market of a product,
uniquely identifies the firm of a product (corresponds to column number in the ownership matrix).
https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/26803/SOF9FW&version=1.0
Product data of Nevo's cereal example.
productData_cereal
productData_cereal
A data frame with product data of 24 cereals in each of 94 markets.
cereals market share,
cereals price,
constant,
cereals sugar,
cereals mushy,
market identifier,
uniquely identifies a product in a market,
uniquely identifies a product in a market,
1. instrument,
2. instrument,
3. instrument,
4. instrument,
5. instrument,
6. instrument,
7. instrument,
8. instrument,
9. instrument,
10. instrument,
11. instrument,
12. instrument,
13. instrument,
14. instrument,
15. instrument,
16. instrument,
17. instrument,
18. instrument,
19. instrument,
20. instrument
https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/26803/SOF9FW&version=1.0
This function creates a simulated BLP dataset.
simulate_BLP_dataset( nmkt, nbrn, Xlin, Xexo, Xrandom, instruments, true.parameters = list(), price.endogeneity = list(mean.xi = -2, mean.eita = 0, cov = cbind(c(1, 0.7), c(0.7, 1))), printlevel = 1, seed )
simulate_BLP_dataset( nmkt, nbrn, Xlin, Xexo, Xrandom, instruments, true.parameters = list(), price.endogeneity = list(mean.xi = -2, mean.eita = 0, cov = cbind(c(1, 0.7), c(0.7, 1))), printlevel = 1, seed )
nmkt |
number of markets |
nbrn |
number of products |
Xlin |
character vector specifying the set of linear variables |
Xexo |
character vector specifying the set of exogenous variables (subset of |
Xrandom |
character vector specifying the set of random coefficients (subset of |
instruments |
character vector specifying the set of instrumental variables |
true.parameters |
list with parameters of the DGP
|
price.endogeneity |
list with arguments of the multivariate normal distribution
|
printlevel |
0 (no output) 1 (summary of generated data) |
seed |
seed for the random number generator |
The dataset is balanced, so every market has the same amount of products.
Only unobserved heterogeneity can be considered.
Variables that enter the equation as a Random Coefficient or
exogenously must be included in the set of linear variables.
The parameter.list
argument specifies the "true" effect on the
individual utility for each component. Prices are generated endogenous
as a function of exogenous variables and instruments, where the
respective effect sizes are specified in instrument.effects
and instrument.Xexo.effects
. Error terms xi
and eita
are drawn from a multivariate normal distribution, whose
parameters can be set in price.endogeneity
. Market shares
are generated by MLHS integration rule with 10000 nodes.
Returns a simulated BLP dataset.
K<-2 #number of random coefficients
K<-2 #number of random coefficients
Parameter starting guesses for Nevo's cereal example.
theta_guesses_cereal
theta_guesses_cereal
A matrix with 4 random coefficients (rows) and columns for 4 demographics and one unobserved heterogeneity column (5 cols in total).
https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/26803/SOF9FW&version=1.0
Updates the set of linear, exogenous, random coefficient, share or mean utility variable in the data object.
update_BLP_data(data_update, blp_data)
update_BLP_data(data_update, blp_data)
data_update |
data.frame with variables to update (must contain the market_identifier and product_identifier variables as in |
blp_data |
data object created by the function |
Returns an object of class blp_data
.
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) new_data <- data.frame(price = seq(1,10,length.out=500), x1 = seq(2,10,length.out=500), cdid = sort(rep(1:25,20)), prod_id = rep(1:20,25) ) blp_data_example_updated <-update_BLP_data(blp_data = blp_data, data_update = new_data)
K<-2 #number of random coefficients data <- simulate_BLP_dataset(nmkt = 25, nbrn = 20, Xlin = c("price", "x1", "x2", "x3", "x4", "x5"), Xexo = c("x1", "x2", "x3", "x4", "x5"), Xrandom = paste0("x",1:K),instruments = paste0("iv",1:10), true.parameters = list(Xlin.true.except.price = rep(0.2,5), Xlin.true.price = -0.2, Xrandom.true = rep(2,K), instrument.effects = rep(2,10), instrument.Xexo.effects = rep(1,5)), price.endogeneity = list( mean.xi = -2, mean.eita = 0, cov = cbind( c(1,0.7), c(0.7,1))), printlevel = 0, seed = 234234 ) model <- as.formula("shares ~ price + x1 + x2 + x3 + x4 + x5 | x1 + x2 + x3 + x4 + x5 | 0+ x1 + x2 | iv1 + iv2 + iv3 + iv4 + iv5 + iv6 + iv7 + iv8 +iv9 +iv10" ) blp_data <- BLP_data(model = model, market_identifier="cdid", product_id = "prod_id", productData = data, integration_method = "MLHS" , integration_accuracy = 40, integration_seed = 1) new_data <- data.frame(price = seq(1,10,length.out=500), x1 = seq(2,10,length.out=500), cdid = sort(rep(1:25,20)), prod_id = rep(1:20,25) ) blp_data_example_updated <-update_BLP_data(blp_data = blp_data, data_update = new_data)
Mean utility starting guesses for Nevo's cereal example.
w_guesses_cereal
w_guesses_cereal
A numeric vector of 2256 values.
https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/26803/SOF9FW&version=1.0