Description Usage Arguments Value Examples
View source: R/estimate_demand.R
Estimate a Demand Model From Aggregate Market Shares
1 2 3 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # 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')
## 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)
# 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')
## 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)
# 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')
## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.