diff --git a/Scripts/create_tables.R b/Scripts/create_tables.R index 588d3926bde0ed4baf1cbc8f1f5c1f4588662f55..45600ebe9b2d13d0c9d73a73b421b557e1109bb7 100644 --- a/Scripts/create_tables.R +++ b/Scripts/create_tables.R @@ -26,7 +26,7 @@ texreg(l=list(ols_percentage_correct_control_A, ols_time_spent_control_A, ols_ti natural relatedness index. Female is a dummy variable denoting gender, Age has been mean-centered and measured in years, Income is a continuous variable indicating a transition from one income group to the next higher, and University Degree is a dummy variable indicating whether an individual holds a university degree; (iii) %stars and standard errors in parentheses.", - label = "tab:mani", + label = "tab:olsA", caption = "Results of OLS regressions for Scenario Case A.", file="Tables/ols/ols_A.tex") @@ -44,7 +44,7 @@ texreg(l=list(ols_percentage_correct_control_D, ols_time_spent_control_D, ols_ti natural relatedness index. Female is a dummy variable denoting gender, Age has been mean-centered and measured in years, Income is a continuous variable indicating a transition from one income group to the next higher, and University Degree is a dummy variable indicating whether an individual holds a university degree; (iii) %stars and standard errors in parentheses.", - label = "tab:mani", + label = "tab:olsD", caption = "Results of OLS regressions for Scenario Case B.", file="Tables/ols/ols_D.tex") diff --git a/Scripts/data_prep.R b/Scripts/data_prep.R index 8f695328cc4319720b79fe9dda01c1116d91112a..5627a1cf170e9f75fbb5910c57f0da1aae6f28fe 100644 --- a/Scripts/data_prep.R +++ b/Scripts/data_prep.R @@ -19,7 +19,8 @@ database_full <- database_full %>% mutate(Gender_female = case_when(Gender == 2 Kids_Dummy = case_when(Number_Kids > 0 ~ 1, TRUE ~0), Employment_full = case_when(Employment_type == 1 ~ 1, TRUE~0), Pensioner = case_when(Employment_type == 6 ~ 1, TRUE~0), - Age_mean = Age - mean(Age)) + Age_mean = Age - mean(Age), + Income_mean = QFIncome - mean(QFIncome)) # Data cleaning diff --git a/Scripts/mxl/mxl_wtp_space_caseD_RentINT_NR.R b/Scripts/mxl/mxl_wtp_space_caseD_RentINT_NR.R new file mode 100644 index 0000000000000000000000000000000000000000..d0d686c41cd9b909b7619fb4928e056dfb489444 --- /dev/null +++ b/Scripts/mxl/mxl_wtp_space_caseD_RentINT_NR.R @@ -0,0 +1,187 @@ +#### Apollo standard script ##### + +library(apollo) # Load apollo package + + + +# Test treatment effect + +database <- database_full %>% + filter(!is.na(Treatment_new)) %>% + mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0), + Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0), + Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) + +table(database$Dummy_Treated) +table(database$Dummy_Vol_Treated) +table(database$Dummy_no_info) + +#initialize model + +apollo_initialise() + + +### Set core controls +apollo_control = list( + modelName = "MXL_wtp_Case_D_NR", + modelDescr = "MXL wtp space Case D NR", + indivID ="id", + mixing = TRUE, + HB= FALSE, + nCores = n_cores, + outputDirectory = "Estimation_results/mxl" +) + +##### Define model parameters depending on your attributes and model specification! #### +# set values to 0 for conditional logit model + +apollo_beta=c(mu_natural = 15, + mu_walking = -1, + mu_rent = -2, + ASC_sq = 0, + mu_ASC_sq_treated = 0, + mu_ASC_sq_vol_treated = 0, + mu_ASC_sq_no_info = 0, + mu_ASC_NR = 0, + mu_rent_treated = 0, + mu_rent_vol_treated = 0, + mu_rent_no_info = 0, + mu_rent_NR = 0, + mu_nat_treated =0, + mu_nat_vol_treated = 0, + mu_nat_no_info = 0, + mu_nat_NR = 0, + mu_walking_treated =0, + mu_walking_vol_treated = 0, + mu_walking_no_info = 0, + mu_walking_NR = 0, + sig_natural = 15, + sig_walking = 2, + sig_rent = 2, + sig_ASC_sq = 2) + +### specify parameters that should be kept fixed, here = none +apollo_fixed = c() + +### Set parameters for generating draws, use 2000 sobol draws +apollo_draws = list( + interDrawsType = "sobol", + interNDraws = n_draws, + interUnifDraws = c(), + interNormDraws = c("draws_natural", "draws_walking", "draws_rent", "draws_asc"), + intraDrawsType = "halton", + intraNDraws = 0, + intraUnifDraws = c(), + intraNormDraws = c() +) + +### Create random parameters, define distribution of the parameters +apollo_randCoeff = function(apollo_beta, apollo_inputs){ + randcoeff = list() + + randcoeff[["b_mu_natural"]] = mu_natural + sig_natural * draws_natural + randcoeff[["b_mu_walking"]] = mu_walking + sig_walking * draws_walking + randcoeff[["b_mu_rent"]] = -exp(mu_rent + sig_rent * draws_rent) + randcoeff[["b_ASC_sq"]] = ASC_sq + sig_ASC_sq * draws_asc + + return(randcoeff) +} + + +### validate +apollo_inputs = apollo_validateInputs() +apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){ + + ### Function initialisation: do not change the following three commands + ### Attach inputs and detach after function exit + apollo_attach(apollo_beta, apollo_inputs) + on.exit(apollo_detach(apollo_beta, apollo_inputs)) + + ### Create list of probabilities P + P = list() + + #### List of utilities (later integrated in mnl_settings below) #### + # Define utility functions here: + + V = list() + V[['alt1']] = -(b_mu_rent + mu_rent_treated *Dummy_Treated + mu_rent_vol_treated * Dummy_Vol_Treated + mu_rent_no_info * Dummy_no_info + + mu_rent_NR * Z_Mean_NR)* + (b_mu_natural * Naturalness_1 + b_mu_walking * WalkingDistance_1 + + + mu_nat_treated * Naturalness_1 *Dummy_Treated + mu_nat_no_info * Naturalness_1 * Dummy_no_info + + mu_nat_vol_treated * Naturalness_1 * Dummy_Vol_Treated + + mu_walking_treated * WalkingDistance_1 *Dummy_Treated + mu_walking_no_info * WalkingDistance_1 * Dummy_no_info + + mu_walking_vol_treated * WalkingDistance_1 * Dummy_Vol_Treated + + mu_nat_NR * Z_Mean_NR *Naturalness_1 + + + mu_walking_NR * Z_Mean_NR * WalkingDistance_1 + - Rent_1) + + V[['alt2']] = -(b_mu_rent + mu_rent_treated *Dummy_Treated + mu_rent_vol_treated * Dummy_Vol_Treated + mu_rent_no_info * Dummy_no_info + + mu_rent_NR * Z_Mean_NR)* + (b_mu_natural * Naturalness_2 + b_mu_walking * WalkingDistance_2 + + mu_nat_treated * Naturalness_2 *Dummy_Treated + mu_nat_no_info * Naturalness_2 * Dummy_no_info + + mu_nat_vol_treated * Naturalness_2 * Dummy_Vol_Treated + + mu_walking_treated * WalkingDistance_2 *Dummy_Treated + mu_walking_no_info * WalkingDistance_2 * Dummy_no_info + + mu_walking_vol_treated * WalkingDistance_2 * Dummy_Vol_Treated + + mu_nat_NR * Z_Mean_NR *Naturalness_2 + + + mu_walking_NR * Z_Mean_NR * WalkingDistance_2 + - Rent_2) + + V[['alt3']] = -(b_mu_rent + mu_rent_treated *Dummy_Treated + mu_rent_vol_treated * Dummy_Vol_Treated + mu_rent_no_info * Dummy_no_info + + mu_rent_NR * Z_Mean_NR)* + (b_ASC_sq + b_mu_natural * Naturalness_3 + b_mu_walking * WalkingDistance_3 + + mu_nat_treated * Naturalness_3 *Dummy_Treated + mu_nat_no_info * Naturalness_3 * Dummy_no_info + + mu_nat_vol_treated * Naturalness_3 * Dummy_Vol_Treated + + mu_walking_treated * WalkingDistance_3 *Dummy_Treated + mu_walking_no_info * WalkingDistance_3 * Dummy_no_info + + mu_walking_vol_treated * WalkingDistance_3 * Dummy_Vol_Treated + + mu_ASC_sq_treated * Dummy_Treated + mu_ASC_sq_vol_treated * Dummy_Vol_Treated + + mu_ASC_sq_no_info * Dummy_no_info + + mu_ASC_NR * Z_Mean_NR + + mu_nat_NR * Z_Mean_NR *Naturalness_3 + + mu_walking_NR * Z_Mean_NR * WalkingDistance_3 + - Rent_3) + + + ### Define settings for MNL model component + mnl_settings = list( + alternatives = c(alt1=1, alt2=2, alt3=3), + avail = 1, # all alternatives are available in every choice + choiceVar = choice, + V = V#, # tell function to use list vector defined above + + ) + + ### Compute probabilities using MNL model + P[['model']] = apollo_mnl(mnl_settings, functionality) + + ### Take product across observation for same individual + P = apollo_panelProd(P, apollo_inputs, functionality) + + ### Average across inter-individual draws - nur bei Mixed Logit! + P = apollo_avgInterDraws(P, apollo_inputs, functionality) + + ### Prepare and return outputs of function + P = apollo_prepareProb(P, apollo_inputs, functionality) + return(P) +} + + + +# ################################################################# # +#### MODEL ESTIMATION ## +# ################################################################# # +# estimate model with bfgs algorithm + +mxl_wtp_case_d_rent_NR = apollo_estimate(apollo_beta, apollo_fixed, + apollo_probabilities, apollo_inputs, + estimate_settings=list(maxIterations=400, + estimationRoutine="bfgs", + hessianRoutine="analytic")) + + + +# ################################################################# # +#### MODEL OUTPUTS ## +# ################################################################# # +apollo_saveOutput(mxl_wtp_case_d_rent_NR) + + diff --git a/Scripts/mxl/mxl_wtp_space_caseD_RentINT_X.R b/Scripts/mxl/mxl_wtp_space_caseD_RentINT_X.R index 612c5147efe4a31b13964b4ad4d2bb2687a67d70..2b16bb087a277655f659d410f95011ad3355c802 100644 --- a/Scripts/mxl/mxl_wtp_space_caseD_RentINT_X.R +++ b/Scripts/mxl/mxl_wtp_space_caseD_RentINT_X.R @@ -113,31 +113,31 @@ apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimat V = list() V[['alt1']] = -(b_mu_rent + mu_rent_treated *Dummy_Treated + mu_rent_vol_treated * Dummy_Vol_Treated + mu_rent_no_info * Dummy_no_info - + mu_rent_NR * Z_Mean_NR + mu_rent_Age * Age_mean + mu_rent_Income * QFIncome)* + + mu_rent_NR * Z_Mean_NR + mu_rent_Age * Age_mean + mu_rent_Income * Income_mean)* (b_mu_natural * Naturalness_1 + b_mu_walking * WalkingDistance_1 + + mu_nat_treated * Naturalness_1 *Dummy_Treated + mu_nat_no_info * Naturalness_1 * Dummy_no_info + mu_nat_vol_treated * Naturalness_1 * Dummy_Vol_Treated + mu_walking_treated * WalkingDistance_1 *Dummy_Treated + mu_walking_no_info * WalkingDistance_1 * Dummy_no_info + mu_walking_vol_treated * WalkingDistance_1 * Dummy_Vol_Treated + mu_nat_NR * Z_Mean_NR *Naturalness_1 + mu_nat_Age * Age_mean * Naturalness_1 - + mu_nat_Income * QFIncome * Naturalness_1 + mu_walking_NR * Z_Mean_NR * WalkingDistance_1 - + mu_walking_Age * Age_mean * WalkingDistance_1 + mu_walking_Income * QFIncome * WalkingDistance_1 + + mu_nat_Income * Income_mean * Naturalness_1 + mu_walking_NR * Z_Mean_NR * WalkingDistance_1 + + mu_walking_Age * Age_mean * WalkingDistance_1 + mu_walking_Income * Income_mean * WalkingDistance_1 - Rent_1) V[['alt2']] = -(b_mu_rent + mu_rent_treated *Dummy_Treated + mu_rent_vol_treated * Dummy_Vol_Treated + mu_rent_no_info * Dummy_no_info - + mu_rent_NR * Z_Mean_NR + mu_rent_Age * Age_mean + mu_rent_Income * QFIncome)* + + mu_rent_NR * Z_Mean_NR + mu_rent_Age * Age_mean + mu_rent_Income * Income_mean)* (b_mu_natural * Naturalness_2 + b_mu_walking * WalkingDistance_2 + mu_nat_treated * Naturalness_2 *Dummy_Treated + mu_nat_no_info * Naturalness_2 * Dummy_no_info + mu_nat_vol_treated * Naturalness_2 * Dummy_Vol_Treated + mu_walking_treated * WalkingDistance_2 *Dummy_Treated + mu_walking_no_info * WalkingDistance_2 * Dummy_no_info + mu_walking_vol_treated * WalkingDistance_2 * Dummy_Vol_Treated + mu_nat_NR * Z_Mean_NR *Naturalness_2 + mu_nat_Age * Age_mean * Naturalness_2 - + mu_nat_Income * QFIncome * Naturalness_2 + mu_walking_NR * Z_Mean_NR * WalkingDistance_2 - + mu_walking_Age * Age_mean * WalkingDistance_2 + mu_walking_Income * QFIncome * WalkingDistance_2 + + mu_nat_Income * Income_mean * Naturalness_2 + mu_walking_NR * Z_Mean_NR * WalkingDistance_2 + + mu_walking_Age * Age_mean * WalkingDistance_2 + mu_walking_Income * Income_mean * WalkingDistance_2 - Rent_2) V[['alt3']] = -(b_mu_rent + mu_rent_treated *Dummy_Treated + mu_rent_vol_treated * Dummy_Vol_Treated + mu_rent_no_info * Dummy_no_info - + mu_rent_NR * Z_Mean_NR + mu_rent_Age * Age_mean + mu_rent_Income * QFIncome)* + + mu_rent_NR * Z_Mean_NR + mu_rent_Age * Age_mean + mu_rent_Income * Income_mean)* (b_ASC_sq + b_mu_natural * Naturalness_3 + b_mu_walking * WalkingDistance_3 + mu_nat_treated * Naturalness_3 *Dummy_Treated + mu_nat_no_info * Naturalness_3 * Dummy_no_info + mu_nat_vol_treated * Naturalness_3 * Dummy_Vol_Treated @@ -145,10 +145,10 @@ apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimat + mu_walking_vol_treated * WalkingDistance_3 * Dummy_Vol_Treated + mu_ASC_sq_treated * Dummy_Treated + mu_ASC_sq_vol_treated * Dummy_Vol_Treated + mu_ASC_sq_no_info * Dummy_no_info - + mu_ASC_NR * Z_Mean_NR + mu_ASC_Age * Age_mean + mu_ASC_Income * QFIncome + + mu_ASC_NR * Z_Mean_NR + mu_ASC_Age * Age_mean + mu_ASC_Income * Income_mean + mu_nat_NR * Z_Mean_NR *Naturalness_3 + mu_nat_Age * Age_mean * Naturalness_3 - + mu_nat_Income * QFIncome * Naturalness_3 + mu_walking_NR * Z_Mean_NR * WalkingDistance_3 - + mu_walking_Age * Age_mean * WalkingDistance_3 + mu_walking_Income * QFIncome * WalkingDistance_3 + + mu_nat_Income * Income_mean * Naturalness_3 + mu_walking_NR * Z_Mean_NR * WalkingDistance_3 + + mu_walking_Age * Age_mean * WalkingDistance_3 + mu_walking_Income * Income_mean * WalkingDistance_3 - Rent_3)