Estimate a Demand Model From Aggregate Market Shares
estimate_demand(df, market_ids, product_id, market_share, outside_share, exog_charac, price, nest_shares = NULL, instruments = NULL, productFE = TRUE, marketFE = "both", supply_side = FALSE)
df | Dataframe to containing data to be used in estimation |
---|---|
market_ids | List of variables contaning market identifiers |
product_id | Variable containing product identifier |
market_share | Variable containing product market shares, as a character string |
outside_share | Variable outside shares, as a character string |
exog_charac | Vector of exogenous product characteristic variables, as a character vector |
price | Variable containing market price, as a character string |
nest_shares | Vector of nest share variables, as a character vector |
instruments | Vector of instrument names, as a character vector - NOT CURRENTLY IMPLEMENTED |
productFE | Logical variable, |
marketFE | Character string of which market fixed effects to contain, takes value "both", "geog" or "time" |
supply_side | Logical variable, |
Returns an object of class "lm" when instruments = FALSE
# Regression Without Nests mkts <- create_markets(geog_id = "market_id", time_id = "year") price_var <- c("price_euro") exog_var <- c("kilowatts", "fueleff_avg", "width", "height", "domestic") mkt_share <- c("mkt_share") outside_share <- c("outside_share") ## Create Shares df <- mkt_share_from_sales(eurocars, quantity = 'qty_sold', population = 'population') df2 <- create_shares(df, market_id = mkts, mkt_share = 'mkt_share')#> [1] "Creating Outside Share..." #> [1] "Done!"## Run regression reg <- estimate_demand(df = df2, market_ids = mkts, product_id = 'model_id2', market_share = mkt_share, outside_share = outside_share, exog_charac = exog_var, price = price_var, marketFE = "both", productFE = TRUE)#> [1] "Estimation With Geographic and Time Fixed Effects" #> [1] "Estimation With Product Fixed Effects"# Regression With One Level Nest mkts <- create_markets(geog_id = "market_id", time_id = "year") price_var <- c("price_euro") exog_var <- c("kilowatts", "fueleff_avg", "width", "height", "domestic") mkt_share <- c("mkt_share") outside_share <- c("outside_share") ## Create Shares df <- mkt_share_from_sales(eurocars, quantity = 'qty_sold', population = 'population') df2 <- create_shares(df, market_id = mkts, mkt_share = 'mkt_share', nest_id = 'class_id')#> [1] "Creating Outside Share..." #> [1] "Done!" #> [1] "Working with one layer of nests..." #> [1] "Nest ID is: class_id"## Run regression reg <- estimate_demand(df = df2, market_ids = mkts, product_id = 'model_id2', market_share = mkt_share, outside_share = outside_share, exog_charac = exog_var, price = price_var, nest_shares = c("within_nest"), marketFE = "both", productFE = TRUE)#> [1] "Estimation With Geographic and Time Fixed Effects" #> [1] "Estimation With Product Fixed Effects"# Regression With Two Level Nest mkts <- create_markets(geog_id = "market_id", time_id = "year") price_var <- c("price_euro") exog_var <- c("kilowatts", "fueleff_avg", "width", "height", "domestic") mkt_share <- c("mkt_share") outside_share <- c("outside_share") ## Create Shares df <- mkt_share_from_sales(eurocars, quantity = 'qty_sold', population = 'population') df2 <- create_shares(df, market_id = mkts, mkt_share = 'mkt_share', nest_id = 'class_id', subnest_id = 'domestic')#> [1] "Creating Outside Share..." #> [1] "Done!" #> [1] "Working with two layers of nests..." #> [1] "Nest ID is: class_id" #> [1] "Sub-Nest ID is: domestic"## Run regression reg <- estimate_demand(df = df2, market_ids = mkts, product_id = 'model_id2', market_share = mkt_share, outside_share = outside_share, exog_charac = exog_var, price = price_var, nest_shares = c("within_nest", "within_subnest"), marketFE = "both", productFE = TRUE)#> [1] "Estimation With Geographic and Time Fixed Effects" #> [1] "Estimation With Product Fixed Effects"