---
title: "Code and Replication for 'Determinants of the Adoption of Fungus-resistant Grapevines: Evidence from Switzerland'"
author:
date: "`r Sys.Date()` | validate version `r packageVersion('validate')`"
mainfont: Roboto Condensed Light
mathfont: FiraMath-Regular.otf
monofont: Roboto Mono
output: 
  pdf_document:
    number_sections: yes
    toc: TRUE
    toc_depth: 4
header-includes:
  - |
    ```{=latex}
    \usepackage{fvextra}
    \DefineVerbatimEnvironment{Highlighting}{Verbatim}{
      breaksymbolleft={}, 
      showspaces = false,
      showtabs = false,
      breaklines,
      commandchars=\\\{\}
    }
    \usepackage{authblk}
    \author{Lucca Zachmann\footnote{Corresponding e-mail: lzachmann@ethz.ch}}
    \author{Chloe McCallum}
    \author{Robert Finger}
    \affil{Agricultural Economics and Policy Group, ETH Zurich}
    ```
---

\newpage

# Licence
This script can be used for use, reproduction, and distribution under the [Apache License 2.0](https://opensource.org/license/apache-2-0/) terms and conditions.

# Loading data
The data used for this article comes from [https://www.research-collection.ethz.ch/handle/20.500.11850/568595](https://www.research-collection.ethz.ch/handle/20.500.11850/568595) and is publicly available.

```{r loadingData, include = TRUE}
path <- "https://www.research-collection.ethz.ch/bitstream/handle/20.500.11850/568595/dataset.csv"
data <- read.table(path, sep = ";", header = TRUE, na.string = "NA")
```

# Loading packages
Several packages are used.

```{r loadingPackages, include = TRUE, echo = TRUE, message = FALSE, warning = FALSE}
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, stargazer, corrplot, Hmisc, ggpubr, sf, sp, rgdal, raster,
               multiwayvcov, lmtest, conflicted, iml, car, forestmangr, broom, ggrepel, 
               glmnet, gamlr, table1, ggcorrplot, latex2exp, glmnet)

knitr::opts_chunk$set(tidy.opts = list(width.cutoff = 60), tidy = TRUE, booktabs = TRUE)

# Conflicts
conflict_prefer("filter", "dplyr")
conflict_prefer("select", "dplyr")
```

# Data preparation

```{r dataPreparation, include = TRUE, message = FALSE, warning = FALSE}
## Define PIWI variable
data$piwi <- 0
data$piwi[data$VarGrown.Divico == 1 |
               data$VarGrown.Johanniter == 1 |
               data$VarGrown.Baco_noir == 1 |
               data$VarGrown.Birstaler_muscat == 1 |
               data$VarGrown.Bluetenmuskateller == 1 |
               data$VarGrown.Bronner == 1 |
               data$VarGrown.Cabernet_cortis == 1 |
               data$VarGrown.Cabernet_jura == 1 |
               data$VarGrown.Cabernet_noir == 1 |
               data$VarGrown.Cabernello == 1 |
               data$VarGrown.Cabernet_blanc == 1 |
               data$VarGrown.Cabernet_cantor == 1 |
               data$VarGrown.Cabernet_carol == 1 |
               data$VarGrown.Cabernet_eidos == 1 |
               data$VarGrown.Cabertin == 1 |
               data$VarGrown.Divona == 1 |
               data$VarGrown.Donauriesling == 1 |
               data$VarGrown.GF_48_12 == 1 |
               data$VarGrown.IRAC_1933 == 1 |
               data$VarGrown.Laurot == 1 |
               data$VarGrown.Leon_millot == 1 |
               data$VarGrown.Marechal_foch == 1 |
               data$VarGrown.Marechal_foch_leon_millot == 1 |
               data$VarGrown.Monarch == 1 |
               data$VarGrown.Muscaris == 1 |
               data$VarGrown.Muscat_bleu == 1 |
               data$VarGrown.Orion == 1 |
               data$VarGrown.Pinot_nova == 1 |
               data$VarGrown.Pinotin == 1 |
               data$VarGrown.Prior == 1 |
               data$VarGrown.Rondo == 1 |
               data$VarGrown.Saphira == 1 |
               data$VarGrown.Satin_noir == 1 |
               data$VarGrown.Sauvitage == 1 |
               data$VarGrown.Souvignier_gris == 1 |
               data$VarGrown.Sauvignon_soyhieres == 1 |
               data$VarGrown.Seyval_blanc == 1 |
               data$VarGrown.Solaris == 1 |
               data$VarGrown.Triomphe_d_alsace == 1 |
               data$VarGrown.VB_cal_6_04 == 1 |
               data$VarGrown.VB_cal_1_28 == 1 |
               data$VarGrown.VB_cal_1_22 == 1 |
               data$VarGrown.VB_cal_1_36 == 1 |
               data$VarGrown.VB_cal_1_14 == 1 |
               data$VarGrown.VB_cal_1_21 == 1 |
               data$VarGrown.VB_cal_1_15 == 1 |
               data$VarGrown.VB_cal_1_20 == 1 |
               data$VarGrown.VB_cal_82_6 == 1 |
               data$VarGrown.Vidal_blanc == 1] <- 1

data$area_piwi <- ifelse(is.na(data$VarArea.Divico), 0, data$VarArea.Divico) +
  ifelse(is.na(data$VarArea.Johanniter), 0, data$VarArea.Johanniter) +
  ifelse(is.na(data$VarArea.Baco_noir), 0, data$VarArea.Baco_noir) +
  ifelse(is.na(data$VarArea.Birstaler_muscat), 0, data$VarArea.Birstaler_muscat) +
  ifelse(is.na(data$VarArea.Bluetenmuskateller), 0, data$VarArea.Bluetenmuskateller) +
  ifelse(is.na(data$VarArea.Bronner), 0, data$VarArea.Bronner) +
  ifelse(is.na(data$VarArea.Cabernet_cortis), 0, data$VarArea.Cabernet_cortis) +
  ifelse(is.na(data$VarArea.Cabernet_jura), 0, data$VarArea.Cabernet_jura) +
  ifelse(is.na(data$VarArea.Cabernet_noir), 0, data$VarArea.Cabernet_noir) +
  ifelse(is.na(data$VarArea.Cabernello), 0, data$VarArea.Cabernello) +
  ifelse(is.na(data$VarArea.Cabernet_blanc), 0, data$VarArea.Cabernet_blanc) +
  ifelse(is.na(data$VarArea.Cabernet_cantor), 0, data$VarArea.Cabernet_cantor) +
  ifelse(is.na(data$VarArea.Cabernet_carol), 0, data$VarArea.Cabernet_carol) +
  ifelse(is.na(data$VarArea.Cabernet_eidos), 0, data$VarArea.Cabernet_eidos) +
  ifelse(is.na(data$VarArea.Cabertin), 0, data$VarArea.Cabertin) +
  ifelse(is.na(data$VarArea.Divona), 0, data$VarArea.Divona) +
  ifelse(is.na(data$VarArea.Donauriesling), 0, data$VarArea.Donauriesling) +
  ifelse(is.na(data$VarArea.GF_48_12), 0, data$VarArea.GF_48_12) +
  ifelse(is.na(data$VarArea.IRAC_1933), 0, data$VarArea.IRAC_1933) +
  ifelse(is.na(data$VarArea.Laurot), 0, data$VarArea.Laurot) +
  ifelse(is.na(data$VarArea.Leon_millot), 0, data$VarArea.Leon_millot) +
  ifelse(is.na(data$VarArea.Marechal_foch), 0, data$VarArea.Marechal_foch) +
  ifelse(is.na(data$VarArea.Marechal_foch_leon_millot), 0, data$VarArea.Marechal_foch_leon_millot) +
  ifelse(is.na(data$VarArea.Monarch), 0, data$VarArea.Monarch) +
  ifelse(is.na(data$VarArea.Muscaris), 0, data$VarArea.Muscaris) +
  ifelse(is.na(data$VarArea.Muscat_bleu), 0, data$VarArea.Muscat_bleu) +
  ifelse(is.na(data$VarArea.Orion), 0, data$VarArea.Orion) +
  ifelse(is.na(data$VarArea.Pinot_nova), 0, data$VarArea.Pinot_nova) +
  ifelse(is.na(data$VarArea.Pinotin), 0, data$VarArea.Pinotin) +
  ifelse(is.na(data$VarArea.Prior), 0, data$VarArea.Prior) +
  ifelse(is.na(data$VarArea.Rondo), 0, data$VarArea.Rondo) +
  ifelse(is.na(data$VarArea.Saphira), 0, data$VarArea.Saphira) +
  ifelse(is.na(data$VarArea.Satin_noir), 0, data$VarArea.Satin_noir) +
  ifelse(is.na(data$VarArea.Sauvitage), 0, data$VarArea.Sauvitage) +
  ifelse(is.na(data$VarArea.Souvignier_gris), 0, data$VarArea.Souvignier_gris) +
  ifelse(is.na(data$VarArea.Sauvignon_soyhieres), 0, data$VarArea.Sauvignon_soyhieres) +
  ifelse(is.na(data$VarArea.Seyval_blanc), 0, data$VarArea.Seyval_blanc) +
  ifelse(is.na(data$VarArea.Solaris), 0, data$VarArea.Solaris) +
  ifelse(is.na(data$VarArea.Triomphe_d_alsace), 0, data$VarArea.Triomphe_d_alsace) +
  ifelse(is.na(data$VarArea.VB_cal_6_04), 0, data$VarArea.VB_cal_6_04) +
  ifelse(is.na(data$VarArea.VB_cal_1_28), 0, data$VarArea.VB_cal_1_28) +
  ifelse(is.na(data$VarArea.VB_cal_1_22), 0, data$VarArea.VB_cal_1_22) +
  ifelse(is.na(data$VarArea.VB_cal_1_36), 0, data$VarArea.VB_cal_1_36) +
  ifelse(is.na(data$VarArea.VB_cal_1_14), 0, data$VarArea.VB_cal_1_14) +
  ifelse(is.na(data$VarArea.VB_cal_1_21), 0, data$VarArea.VB_cal_1_21) +
  ifelse(is.na(data$VarArea.VB_cal_1_15), 0, data$VarArea.VB_cal_1_15) +
  ifelse(is.na(data$VarArea.VB_cal_1_20), 0, data$VarArea.VB_cal_1_20) +
  ifelse(is.na(data$VarArea.VB_cal_82_6), 0, data$VarArea.VB_cal_82_6) +
  ifelse(is.na(data$VarArea.Vidal_blanc), 0, data$VarArea.Vidal_blanc)

area_data <- data %>%
  select(id, starts_with("VarArea.")) %>%
  mutate_each(funs(replace(., which(is.na(.)), 0))) %>%
  mutate(total_area_grapes = rowSums(across(starts_with("VarArea.")))) %>%
  select(id, total_area_grapes)

data <- merge(data, area_data, by = "id")

data$share_piwi <- data$area_piwi/data$total_area_grapes

### Average land share of adopters
data$share_piwi[is.nan(data$share_piwi)] <- 0

#### Share of land currently devoted to fungus-resistant varieties
mean(data$share_piwi)

#### Share of growers having at least one fungus-resistant variety
mean(data$piwi)

# Expected share
data$expected_share_piwi <- (data$elicitation1.FRGmin. + data$elicitation1.FRGavg. + data$elicitation1.FRGmax.)/3
data$expected_share_piwi <- data$expected_share_piwi/100
data$change_share_piwi <- data$expected_share_piwi-data$share_piwi

#### Share of expected land devoted to fungus-resistant varieties
mean(data$expected_share_piwi)

## Variance
data$scaled_variance_share_piwi <- ((data$elicitation1.FRGmax./100-data$elicitation1.FRGmin./100)^2 + 
                                  (data$elicitation1.FRGavg./100-data$elicitation1.FRGmin./100)*(data$elicitation1.FRGavg./100-data$elicitation1.FRGmax./100))/18
data$variance_share_piwi <- ((data$elicitation1.FRGmax.-data$elicitation1.FRGmin.)^2 + 
                                         (data$elicitation1.FRGavg.-data$elicitation1.FRGmin.)*(data$elicitation1.FRGavg.-data$elicitation1.FRGmax.))/18

summary(data$expected_share_piwi)
mean(data$expected_share_piwi)
sd(data$expected_share_piwi)

## Wine region
data$wine_region[grep("Gen", data$wine_region)] <- "Geneva"
data$wine_region <- factor(data$wine_region,levels = c("Deutschschweiz","Geneva","Ticino",
                                                       "Trois lacs","Valais","Vaud"))

## Adjust production system
### IP
data$production.AO03.[data$production.other. == "Unzertifiziert IP "] <- 1
data$production.AO03.[data$production.other. == "PI/bio"] <- 1
data$production.AO03.[data$production.other. == "PI"] <- 1
data$production.AO03.[data$production.other. == "Pas de label, mais en PI"] <- 1
data$production.AO03.[data$production.other. == "IP aber nicht zertifiziert da Genossenschaft"] <- 1
data$production.AO03.[data$production.other. == "Vinatura"] <- 1

### ÃLN
data$production.AO01.[data$production.other. == "Vinatura"] <- 1
data$production.AO01.[grepl("vinatura", data$production.other.)] <- 1

### BIO
data$production.AO01.[grepl("Bioauthentisch", data$production.other.)] <- 1
data$production.AO01.[grepl("biologisch", data$production.other.)] <- 1
data$production.AO01.[grepl("Biologisch", data$production.other.)] <- 1
data$production.AO01.[grepl("Bio, aber nicht zertifiziert", data$production.other.)] <- 1

## Age
data$age <- 2022-data$DOB

data$female <- 0
data$female[data$gender == "F"] <- 1

data$direct_marketing <- 0
data$direct_marketing[!is.na(data$marketingwines.A1.) & data$marketingwines.A1. > 50] <- 1

data$earning_farming <- 0
data$earning_farming[data$earnings1 == "A4" | data$earnings1 == "A5"] <- 1

data$earning_viticulture <- 0
data$earning_viticulture[data$earnings2 == "A4" | data$earnings2 == "A5"] <- 1

data$ReplantRate <- data$ReplantRate/100

data$successor_var <- 0
data$successor_var[data$successor == "A4" | data$successor == "A5"] <- 1

data$RR_new <- 0
data$RR_new[data$ReplantRate > 0] <- 1
```

# Plots in the Manuscript
Figure 1 is not replicated here due to data privacy (i.e. farm locations).

## Figure 2: Change in expected land share devoted to fungus-resistant varieties per farm and region (percentage points) 
```{r Figure2, include = TRUE, echo = TRUE, message = FALSE, warning = FALSE}

# Change per farm and wine region
df.summary <- data %>%
  group_by(wine_region) %>%
  summarise(
    sd = sd(change_share_piwi, na.rm = TRUE),
    mean = mean(change_share_piwi),
    cur_mean = mean(share_piwi*100),
    exp_mean = mean(expected_share_piwi)
  )

df.summary$change_share_piwi <- (df.summary$exp_mean*100-df.summary$cur_mean)
df.summary$change_share_piwi_label <- as.character(round(df.summary$change_share_piwi,1))

df.long <- df.summary %>%
  select(wine_region, cur_mean, exp_mean) %>%
  gather(type, var, -c(wine_region))

data$change_share_piwi <- data$change_share_piwi*100

Figure2 <- ggplot(data = data, aes(y = change_share_piwi, x = wine_region)) +
  geom_hline(yintercept = 0, color = "red", linewidth = 1, alpha = 0.5) +
  geom_jitter(position = position_jitter(0.2), alpha = 0.75, size = 1.8, color = "grey50") +
  geom_crossbar(data = df.summary, aes(ymin = change_share_piwi, ymax = change_share_piwi),
                size = 0.3,col="black", width = .5) +
  geom_text(data = df.summary, aes(y = change_share_piwi, label = paste0(change_share_piwi_label,""), 
                                 hjust = -1.5, vjust = -0.4), size = 3.5) +
  theme_bw() +
  xlab("The 6 Swiss wine regions") +
  ylab(expression(symbol('\254') * " decrease    " * symbol('\104') * " land share (pp)" * "    increase " * symbol('\256'))) + 
  scale_y_continuous(breaks = c(-100,-50,0,50,100), labels = c("-100","-50","0","50","100"), limits = c(-100,100)) +
  theme(panel.grid.major.x = element_blank(),
        axis.ticks.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.y = element_text(size = 12),
        axis.title.x = element_text(size = 12, margin = margin(t = 20, r = 0, b = 0, l = 0)),
        text = element_text(size = 16)
        ) 

Figure2

ggsave(Figure2, file = "Figure2.png", 
       width = 30, height = 15, units = "cm", dpi = 600, bg = "white")
```

## Figure 3: Coefficient plots and 99%/95% confidence interval from Model 1
```{r Figure3, include = TRUE, results = 'asis', echo = TRUE, message = FALSE, warning = FALSE, fig.height=10, out.width="100%"}
## Simple models

### Drop observations with no replanting
regression_data <- data %>%
  filter(ReplantRate != 0)

regression_data$change_share_piwi <- regression_data$change_share_piwi/100

models_simple <- list(
  m1 <- lm(formula = change_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC +
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + 
             education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + wine_region, data = regression_data),
  m2 <- lm(formula = change_share_piwi ~ wine_region, data = regression_data),
  m3 <- lm(formula = change_share_piwi ~ NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + 
             FRGprecp.FRGmarket. + FRGprecp.FRGwtp. +FRGprecp.FRGqual. + outlook.A5. + wine_region, data = regression_data),
  m4 <- lm(formula = change_share_piwi ~ timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + wine_region, data = regression_data),
  m5 <- lm(formula = change_share_piwi ~ noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m6 <- lm(formula = change_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + 
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate +
             NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + 
             FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. +
             timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + 
             noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data)
)

### Regression table
clwb <- list(
  se1 <- cluster.boot(models_simple[[1]], regression_data$wine_region, boot_type = "wild"),
  se2 <- cluster.boot(models_simple[[2]], regression_data$wine_region, boot_type = "wild"),
  se3 <- cluster.boot(models_simple[[3]], regression_data$wine_region, boot_type = "wild"),
  se4 <- cluster.boot(models_simple[[4]], regression_data$wine_region, boot_type = "wild"),
  se5 <- cluster.boot(models_simple[[5]], regression_data$wine_region, boot_type = "wild"),
  se6 <- cluster.boot(models_simple[[6]], regression_data$wine_region, boot_type = "wild")
)

ct <- list(
  ct1 <- coeftest(models_simple[[1]], clwb[[1]])[, 2],
  ct2 <- coeftest(models_simple[[2]], clwb[[2]])[, 2],
  ct3 <- coeftest(models_simple[[3]], clwb[[3]])[, 2],
  ct4 <- coeftest(models_simple[[4]], clwb[[4]])[, 2],
  ct5 <- coeftest(models_simple[[5]], clwb[[5]])[, 2],
  ct6 <- coeftest(models_simple[[6]], clwb[[6]])[, 2]
)

### Coefficient plot
model_output <- tidy(models_simple[[6]])
out_conf <- tidy(models_simple[[6]], conf.int = TRUE)
lm_model_out <- round_df(out_conf, digits = 4)
lm_model_out <- lm_model_out[-1,] 
names(lm_model_out)[names(lm_model_out) == "term"] <- "factor"

clustered_se <- as.data.frame(ct[[6]]) 
names(clustered_se)[1] <- "ct6"
clustered_se$factor <- row.names(clustered_se)
clustered_se <- clustered_se %>%
  filter(factor != "(Intercept)")

lm_model_out <- merge(lm_model_out, clustered_se, by = "factor")
lm_model_out$CI95_new <- lm_model_out$ct6*3.92
lm_model_out$CI99_new <- lm_model_out$ct6*5.15
lm_model_out$CI95_new_upper <- lm_model_out$estimate+(lm_model_out$CI95_new/2)
lm_model_out$CI95_new_lower <- lm_model_out$estimate-(lm_model_out$CI95_new/2)
lm_model_out$CI99_new_upper <- lm_model_out$estimate+(lm_model_out$CI99_new/2)
lm_model_out$CI99_new_lower <- lm_model_out$estimate-(lm_model_out$CI99_new/2)

# Categorizing
lm_model_out$category <- ""
lm_model_out$category[lm_model_out$factor == "labor"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "age"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "female"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "farmsize"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "earning_farming"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "earning_viticulture"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "AOC"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "labels.Org."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "labels.Demeter."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "labels.IPSuisse."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "direct_marketing"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "retail"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "education1.A7."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "FRGknowledge.SQ001."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "ReplantRate"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "successor_var"] <- "Farmer- and farm\ncharacteristics"

lm_model_out$category[lm_model_out$factor == "avg_oidium"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_region"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionTicino"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionValais"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionVaud"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionTicino"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionTrois lacs"] <- "Regional\ncharacteristics"
lm_model_out$category[grep("Gen", lm_model_out$factor)] <- "Regional\ncharacteristics"

lm_model_out$category[lm_model_out$factor == "NegImpact.A2."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGhealth."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGenv."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGfuture."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGmarket."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGwtp."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGqual."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "outlook.A5."] <- "Perceptions"

lm_model_out$category[lm_model_out$factor == "timepref.timep."] <- "Preferences"
lm_model_out$category[lm_model_out$factor == "riskpref.prodrisk."] <- "Preferences"
lm_model_out$category[lm_model_out$factor == "riskpref.markrisk."] <- "Preferences"
lm_model_out$category[lm_model_out$factor == "riskpref.plantrisk."] <- "Preferences"

lm_model_out$category[lm_model_out$factor == "noncog.SelfHarvest."] <- "Personality\ntraits"
lm_model_out$category[lm_model_out$factor == "noncog.LocusSkills."] <- "Personality\ntraits"
lm_model_out$category[lm_model_out$factor == "noncog.ambitious."] <- "Personality\ntraits"

# Renaming
lm_model_out$factor[lm_model_out$factor == "labor"] <- "Labour"
lm_model_out$factor[lm_model_out$factor == "age"] <- "Age"
lm_model_out$factor[lm_model_out$factor == "female"] <- "Female"
lm_model_out$factor[lm_model_out$factor == "farmsize"] <- "Farmsize"
lm_model_out$factor[lm_model_out$factor == "earning_farming"] <- "Farming specialization"  
lm_model_out$factor[lm_model_out$factor == "earning_viticulture"] <- "Viticulture specialization"
lm_model_out$factor[lm_model_out$factor == "AOC"] <- "Geographical denomination label"
lm_model_out$factor[lm_model_out$factor == "labels.Org."] <- "Organic label"
lm_model_out$factor[lm_model_out$factor == "labels.Demeter."] <- "Bio-dynamic label"
lm_model_out$factor[lm_model_out$factor == "labels.IPSuisse."] <- "Integrated production label"
lm_model_out$factor[lm_model_out$factor == "direct_marketing"] <- "Direct marketing"
lm_model_out$factor[lm_model_out$factor == "retail"] <- "Marketing to retail"
lm_model_out$factor[lm_model_out$factor == "education1.A7."] <- "Further education"
lm_model_out$factor[lm_model_out$factor == "FRGknowledge.SQ001."] <- "Knowledge about FRG"
lm_model_out$factor[lm_model_out$factor == "ReplantRate"] <- "Replantation rate"
lm_model_out$factor[lm_model_out$factor == "successor_var"] <- "Farm successor"
lm_model_out$factor[lm_model_out$factor == "avg_oidium"] <- "Oidium infection risk"
lm_model_out$factor[lm_model_out$factor == "NegImpact.A2."] <- "Fungal damage"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGhealth."] <- "FRG have a positive impact on the human health\nof farmers and communities surrounding farms"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGenv."] <- "FRG varieties are better for the environment"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGfuture."] <- "FRG wine use will increase in the future"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGmarket."] <- "Wine from FRG is difficult to market"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGwtp."] <- "Consumers are willing to pay less for wine from FRG"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGqual."] <- "Wine from FRG is of lower quality\nthan traditional varieties"
lm_model_out$factor[lm_model_out$factor == "outlook.A5."] <- "Banned copper"
lm_model_out$factor[lm_model_out$factor == "timepref.timep."] <- "Time preferences"
lm_model_out$factor[lm_model_out$factor == "riskpref.prodrisk."] <- "Production risk preferences"
lm_model_out$factor[lm_model_out$factor == "riskpref.markrisk."] <- "Market risk preferences"
lm_model_out$factor[lm_model_out$factor == "riskpref.plantrisk."] <- "Plant protection risk preferences"
lm_model_out$factor[lm_model_out$factor == "noncog.SelfHarvest."] <- "Self-efficacy"
lm_model_out$factor[lm_model_out$factor == "noncog.LocusSkills."] <- "Locus of control"
lm_model_out$factor[lm_model_out$factor == "noncog.ambitious."] <- "Ambition"
lm_model_out$factor[lm_model_out$factor == "wine_regionTicino"] <- "Region Ticino"
lm_model_out$factor[lm_model_out$factor == "wine_regionValais"] <- "Region Valais"
lm_model_out$factor[lm_model_out$factor == "wine_regionVaud"] <- "Region Vaud"
lm_model_out$factor[lm_model_out$factor == "wine_regionTrois lacs"] <- "Region Trois lacs"
lm_model_out$factor[grep("Gen", lm_model_out$factor)] <- "Region Geneva"

lm_model_out$sig_estimate <- ifelse(sign(lm_model_out$CI95_new_upper) == sign(lm_model_out$CI95_new_lower), 
                                    as.character(round(lm_model_out$estimate,3)),"")

# Now plot them
Figure3 <- ggplot(lm_model_out, aes(x=reorder(factor, estimate), y=estimate)) +
  geom_hline(yintercept = 0, color = "red", size = 1, alpha = 0.5) +
  geom_linerange(aes(x=reorder(factor, estimate), 
                     ymin = CI95_new_lower,
                     ymax = CI95_new_upper),
                 alpha = 0.8, size = 1, position = position_dodge(width = 1/2)) + 
  geom_linerange(aes(x=reorder(factor, estimate), 
                     ymin = CI99_new_lower,
                     ymax = CI99_new_upper),
                 alpha = 0.4, size = 1, position = position_dodge(width = 1/2)) +
  geom_point(aes(x=reorder(factor, estimate), y=estimate)) + 
  geom_text(aes(x=factor, y=estimate, label=sig_estimate), size = 3.5, vjust = -0.5) +
  xlab("") +
  ylab("Coefficient estimates (and 99%/95% confidence intervals)") +
  geom_point() + 
  facet_grid(category ~ ., space = "free", scales="free", switch="y") +
  coord_flip() +
  theme_minimal() +
  theme(axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 10, l = 0)),
        panel.grid.major.y = element_blank(),
        strip.placement = "outside",
        strip.background = element_rect(fill=NA,colour="black"),
        strip.text.y = element_text(size=10, face = "bold", colour = "black"),
        axis.text.y = element_text(size = 11),
        panel.spacing=unit(0,"cm"))

Figure3

ggsave(Figure3, file = "Figure3.png", 
       width = 30, height = 30, units = "cm", dpi = 600, bg = "white")
```

\newpage

## Figure 4: Relevance of groups on the uptake dynamics of fungus-resistant varieties
```{r Figure4, include = TRUE, results = 'asis', echo = TRUE, message = FALSE, warning = FALSE, out.width="100%"}
## Simple models

### Drop observations with no replanting
regression_data <- data %>%
  filter(ReplantRate != 0)

regression_data$change_share_piwi <- regression_data$change_share_piwi/100

models_simple <- list(
  m1 <- lm(formula = change_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC +
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + 
             education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + wine_region, data = regression_data),
  m2 <- lm(formula = change_share_piwi ~ wine_region, data = regression_data),
  m3 <- lm(formula = change_share_piwi ~ NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + 
             FRGprecp.FRGmarket. + FRGprecp.FRGwtp. +FRGprecp.FRGqual. + outlook.A5. + wine_region, data = regression_data),
  m4 <- lm(formula = change_share_piwi ~ timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + wine_region, data = regression_data),
  m5 <- lm(formula = change_share_piwi ~ noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m6 <- lm(formula = change_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + 
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate +
             NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + 
             FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. +
             timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + 
             noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data)
)

### R-squared

# Farmer- and farm characteristics
summary(models_simple[[1]])$adj.r.squared

# Regional characteristics
summary(models_simple[[2]])$adj.r.squared

# Perceptions
summary(models_simple[[3]])$adj.r.squared

# Preferences
summary(models_simple[[4]])$adj.r.squared

# Personality
summary(models_simple[[5]])$adj.r.squared

# Total
summary(models_simple[[6]])$adj.r.squared

r_squared <- data.frame(name = c("Farmer- and\nfarm characteristics","Regional characteristics","Perceptions",
                                 "Preferences","Personality traits"), 
                        ar2 = c(summary(models_simple[[1]])$adj.r.squared,
                                summary(models_simple[[2]])$adj.r.squared,
                                summary(models_simple[[3]])$adj.r.squared,
                                summary(models_simple[[4]])$adj.r.squared,
                                summary(models_simple[[5]])$adj.r.squared))

r_squared_long <- r_squared %>%
  gather(type, value, -name)

Figure4 <- ggplot(r_squared_long) + 
  geom_bar(
    aes(x = reorder(name, value), y = value, fill = factor(type), group = type), 
    stat='identity', position = 'dodge', width = 0.3, show.legend = FALSE) +
  geom_text(
    aes(x = name, y = value, label = round(value,2), group = type), 
    hjust = -0.5, size = 3,
    position = position_dodge(width = 1),
    inherit.aes = TRUE) + 
  theme_minimal() +
  theme(panel.grid.major.y = element_blank(),
        axis.text.y = element_text(size = 16),
        axis.text.x = element_text(size = 14),
        axis.title.y = element_text(margin = margin(t = 0, r = 0, b = 0, l = 30), size = 16),
        axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0), size = 16)) +
  ylab("Adjusted R-squared") +
  xlab("") +
  scale_y_continuous(limits = c(0,0.25), breaks = c(0,0.05,0.1,0.15,0.2,0.25)) +
  scale_fill_manual(name = "Goodness of fit", values = c("darkgrey","lightgrey"), labels = c("Adj. R-squared","R-squared")) +
  coord_flip() 

Figure4

ggsave(Figure4, file = "Figure4.png", 
       width = 40, height = 20, dpi = 600, units = "cm", bg = "white")
```

\newpage

# Plots and Tables in the Appendix

## Figure A1: Global economic relevance of grapevine production
Data is available from [FAO Data](https://www.fao.org/statistics/en/).

```{r FigureA1, results = 'hide', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
fao_data <- read.csv2("data/FAOSTAT_data_6-9-2022.csv", header = TRUE, sep = ",", dec=",", na.strings=c("NA",""), encoding = "UTF-8") 

# Identify number one crop
fao_data1 <- fao_data %>%
  filter(!grepl("Meat", Item)) %>%
  filter(!grepl("Eggs", Item)) %>%
  filter(!grepl("Milk", Item)) %>%
  group_by(Area, Item) %>%
  summarise(total = sum(Value))

fao_data1 <- fao_data1 %>%
  group_by(Area) %>%
  mutate(sum = sum(total))

fao_data1$share <- fao_data1$total/fao_data1$sum*100

fao_data1 <- fao_data1 %>%
  group_by(Area) %>%
  mutate(max = max(share))

eu_countries <- c("Switzerland","Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Czechia", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden")

fao_data1 <- fao_data1 %>%
  mutate(eu = ifelse(Area %in% eu_countries, 1, 0))

grapes_europe <- fao_data1 %>%
  filter(Item == "Grapes") %>%
  group_by(eu) %>%
  summarise(mean_share = mean(share))

grapes_europe_n1 <- fao_data1 %>%
  filter(eu == 1) %>%
  group_by(Item) %>%
  summarise(mean_share = mean(share))

fao_data1 <- fao_data1 %>%
  filter(max == share)

fao_data$cropIdentifier <- "Rest of the crops"
fao_data$cropIdentifier[fao_data$Item == "Grapes"] <- "Grapes"

fao_data <- fao_data %>%
  filter(!grepl("Meat", Item)) %>%
  filter(!grepl("Eggs", Item)) %>%
  filter(!grepl("Milk", Item))

fao_data <- fao_data %>%
  group_by(Area, cropIdentifier) %>%
  summarise(total = sum(Value))

fao_data <- fao_data %>%
  group_by(Area) %>%
  mutate(sum = sum(total))

fao_data$share <- fao_data$total/fao_data$sum*100

fao_data <- fao_data %>%
  filter(cropIdentifier == "Grapes")

fao_data$Area[fao_data$Area == "Bolivia (Plurinational State of)"] <- "Bolivia"
fao_data$Area[fao_data$Area == "Czechia"] <- "Czech Republic"
fao_data$Area[fao_data$Area == "Bosnia and Herzegovina"] <- "Bosnia & Herzegovina"

# Load world data (https://public.opendatasoft.com/explore/dataset/world-administrative-boundaries/export/)
world_data <- st_read("data/world-administrative-boundaries.shp")

world_data <- merge(world_data, fao_data, by.x = "name", by.y = "Area", all = TRUE)

Figure_A1 <- ggplot() +
  geom_rect(aes(xmin=-180, xmax=180, ymin=-25, ymax=-55), fill = "red", alpha = 0.2) +
  geom_rect(aes(xmin=-180, xmax=180, ymin=25, ymax=55), fill = "red", alpha = 0.2) +
  geom_sf(data = world_data, aes(fill = share), alpha = 1, color = "black", size = 0.2) +
  theme_minimal() +
  scale_fill_gradient(name = "Share of non-animal gross production value of grapes (%)",
                       low = "grey100",
                       high = "darkgreen",
                       na.value="white") +
  xlab("") +
  ylab("") +
  coord_sf(expand = FALSE) +
  theme(axis.text = element_text(size = 6.5),
        panel.grid.major = element_line(colour = "transparent"),
         legend.position = "bottom")   

Figure_A1

ggsave(Figure_A1, file = "Appendix_Figure_A1.png", width = 30, height = 15, dpi = 600, units = "cm", bg = "white")
```

## Table C1: Regression results full table

```{r TableC1, results = 'hide', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
stargazer(c(models_simple),
         se = c(ct),
         title="OLS Results",
         dep.var.labels=c("Change in share of land devoted to fungus-resistant varieties (%)"),
         covariate.labels=c("Labour","Age","Female","Farm size","Farming specialization","Viticulture specialization","Geographical denomination label","Organic label","Bio-dynamic label","Integrated production label","Direct marketing","Further education","Knowledge about FRG","Farm successor","Replantation rate","Fungal damage","FRG have a positive impact on the human health of farmers and communities surrounding farms","FRG varieties are better for the environment","FRG wine use will increase in the future","Wine from FRG is difficult to market","Consumers are willing to pay less for wine from FRG","Wine from FRG is of lower quality than traditional varieties","Banned copper","Time preferences","Production risk preferences","Market risk preferences","Plant protection risk preferences","Self-efficacy","Locus of control","Ambition"),
         omit.stat=c("LL","ser","f"),
         no.space=FALSE,
         align=TRUE,
         single.row = TRUE,
         add.lines=list(c('Wine region dummies', 'Yes','Yes','Yes','Yes','Yes','Yes')),
         notes.align = "l",
         style = "qje",
         notes.append = TRUE,
         column.sep.width = "-25pt",
         notes = "Clustered and wild bootstrapped standard errors at the wine region are shown in parentheses.",
         type='html',
         font.size = "tiny",
         star.char = c("","**", "***"), star.cutoffs = c(0.1, 0.05, 0.01),
         out = "Appendix_Table_C1.doc")
```

## Table D1: Correlations between variables

```{r FigureD1, results = 'asis', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
### Correlation plot
cor_data <- regression_data %>%
  select(labor, age, earning_farming, earning_viticulture, AOC, 
           labels.Org., labels.Demeter., labels.IPSuisse., direct_marketing, education1.A7., FRGknowledge.SQ001., ReplantRate, successor_var,
           avg_oidium, NegImpact.A2., FRGprecp.FRGhealth., FRGprecp.FRGenv., FRGprecp.FRGfuture., FRGprecp.FRGmarket., 
           FRGprecp.FRGwtp., FRGprecp.FRGqual., 
           timepref.timep., riskpref.prodrisk., riskpref.markrisk., riskpref.plantrisk., 
           noncog.SelfHarvest., noncog.LocusSkills., noncog.ambitious., wine_region)

cor_data$`wine_regionTrois lacs` <- ifelse(cor_data$wine_region == "Trois lacs", 1, 0)
cor_data$wine_regionTicino <- ifelse(cor_data$wine_region == "Ticino", 1, 0)
cor_data$wine_regionVaud <- ifelse(cor_data$wine_region == "Vaud", 1, 0)
cor_data$wine_regionValais <- ifelse(cor_data$wine_region == "Valais", 1, 0)
cor_data$wine_regionDeutschschweiz <- ifelse(cor_data$wine_region == "Deutschschweiz", 1, 0)
cor_data$wine_regionGeneva <- ifelse(cor_data$`wine_regionTrois lacs` != 1 & cor_data$wine_regionTicino != 1 & cor_data$wine_regionVaud != 1 &
                                     cor_data$wine_regionValais != 1 & cor_data$wine_regionDeutschschweiz != 1, 1, 0)
cor_data$wine_region <- NULL

cor_data <- cor_data %>%
  drop_na()

corr <- round(cor(cor_data, method = "pearson"), 2)
p.mat <- cor_pmat(cor_data, conf.level = 0.95)

corr <- data.frame(corr)
p.mat <- data.frame(p.mat)

corr_long <- corr %>%
  mutate(row = rownames(corr)) %>%
  gather(key, variable, -row)

p.mat_long <- p.mat %>%
  mutate(row = rownames(p.mat)) %>%
  gather(key, variable, -row)

long_cmd <- merge(corr_long, p.mat_long, by = c("key","row"))

long_cmd <- long_cmd %>%
  filter(variable.x != 1 & variable.y < 0.05)

q <- quantile(abs(long_cmd$variable.x), probs = seq(0, 1, 0.05))

correlations <- long_cmd %>%
  filter(variable.x >= q[20]) #95% percentile

# Renaming
colnames(corr)[colnames(corr) == "labor"] <- "Standardized labour"
colnames(corr)[colnames(corr) == "age"] <- "Age (in years)"
colnames(corr)[colnames(corr) == "earning_farming"] <- "Farming specialization"  
colnames(corr)[colnames(corr) == "earning_viticulture"] <- "Viticulture specialization"
colnames(corr)[colnames(corr) == "AOC"] <- "Geographical denomination label"
colnames(corr)[colnames(corr) == "labels.Org."] <- "Organic label"
colnames(corr)[colnames(corr) == "labels.Demeter."] <- "Bio-dynamic label"
colnames(corr)[colnames(corr) == "labels.IPSuisse."] <- "Integrated production label"
colnames(corr)[colnames(corr) == "direct_marketing"] <- "Direct marketing"
colnames(corr)[colnames(corr) == "retail"] <- "Marketing to retail"
colnames(corr)[colnames(corr) == "education1.A7."] <- "Further education"
colnames(corr)[colnames(corr) == "FRGknowledge.SQ001."] <- "Knowledge about FRG"
colnames(corr)[colnames(corr) == "ReplantRate"] <- "Replantation rate"
colnames(corr)[colnames(corr) == "successor_var"] <- "Farm successor"
colnames(corr)[colnames(corr) == "avg_oidium"] <- "Oidium infection risk"
colnames(corr)[colnames(corr) == "NegImpact.A2."] <- "Fungal damage"
colnames(corr)[colnames(corr) == "FRGprecp.FRGhealth."] <- "FRG have a positive impact on the human health\nof farmers and communities surrounding farms"
colnames(corr)[colnames(corr) == "FRGprecp.FRGenv."] <- "FRG varieties are better for the environment"
colnames(corr)[colnames(corr) == "FRGprecp.FRGfuture."] <- "FRG wine use will increase in the future"
colnames(corr)[colnames(corr) == "FRGprecp.FRGmarket."] <- "Wine from FRG is difficult to market"
colnames(corr)[colnames(corr) == "FRGprecp.FRGwtp."] <- "Consumers are willing to pay less for wine from FRG"
colnames(corr)[colnames(corr) == "FRGprecp.FRGqual."] <- "Wine from FRG is of lower quality\nthan traditional varieties"
colnames(corr)[colnames(corr) == "timepref.timep."] <- "Time preferences"
colnames(corr)[colnames(corr) == "riskpref.prodrisk."] <- "Production risk preferences"
colnames(corr)[colnames(corr) == "riskpref.markrisk."] <- "Market risk preferences"
colnames(corr)[colnames(corr) == "riskpref.plantrisk."] <- "Plant protection risk preferences"
colnames(corr)[colnames(corr) == "noncog.SelfHarvest."] <- "Self-efficacy"
colnames(corr)[colnames(corr) == "noncog.LocusSkills."] <- "Locus of control"
colnames(corr)[colnames(corr) == "noncog.ambitious."] <- "Ambition"
colnames(corr)[colnames(corr) == "wine_regionTicino"] <- "Region Ticino"
colnames(corr)[colnames(corr) == "wine_regionValais"] <- "Region Valais"
colnames(corr)[colnames(corr) == "wine_regionVaud"] <- "Region Vaud"
colnames(corr)[colnames(corr) == "wine_regionTrois lacs"] <- "Region Trois lacs"
colnames(corr)[colnames(corr) == "wine_regionDeutschschweiz"] <- "Region Deutschschweiz"
colnames(corr)[colnames(corr) == "wine_regionGeneva"] <- "Region Geneva"

rownames(corr)[rownames(corr) == "labor"] <- "Standardized labour"
rownames(corr)[rownames(corr) == "age"] <- "Age (in years)"
rownames(corr)[rownames(corr) == "earning_farming"] <- "Farming specialization"  
rownames(corr)[rownames(corr) == "earning_viticulture"] <- "Viticulture specialization"
rownames(corr)[rownames(corr) == "AOC"] <- "Geographical denomination label"
rownames(corr)[rownames(corr) == "labels.Org."] <- "Organic label"
rownames(corr)[rownames(corr) == "labels.Demeter."] <- "Bio-dynamic label"
rownames(corr)[rownames(corr) == "labels.IPSuisse."] <- "Integrated production label"
rownames(corr)[rownames(corr) == "direct_marketing"] <- "Direct marketing"
rownames(corr)[rownames(corr) == "retail"] <- "Marketing to retail"
rownames(corr)[rownames(corr) == "education1.A7."] <- "Further education"
rownames(corr)[rownames(corr) == "FRGknowledge.SQ001."] <- "Knowledge about FRG"
rownames(corr)[rownames(corr) == "ReplantRate"] <- "Replantation rate"
rownames(corr)[rownames(corr) == "successor_var"] <- "Farm successor"
rownames(corr)[rownames(corr) == "avg_oidium"] <- "Oidium infection risk"
rownames(corr)[rownames(corr) == "NegImpact.A2."] <- "Fungal damage"
rownames(corr)[rownames(corr) == "FRGprecp.FRGhealth."] <- "FRG have a positive impact on the human health\nof farmers and communities surrounding farms"
rownames(corr)[rownames(corr) == "FRGprecp.FRGenv."] <- "FRG varieties are better for the environment"
rownames(corr)[rownames(corr) == "FRGprecp.FRGfuture."] <- "FRG wine use will increase in the future"
rownames(corr)[rownames(corr) == "FRGprecp.FRGmarket."] <- "Wine from FRG is difficult to market"
rownames(corr)[rownames(corr) == "FRGprecp.FRGwtp."] <- "Consumers are willing to pay less for wine from FRG"
rownames(corr)[rownames(corr) == "FRGprecp.FRGqual."] <- "Wine from FRG is of lower quality\nthan traditional varieties"
rownames(corr)[rownames(corr) == "timepref.timep."] <- "Time preferences"
rownames(corr)[rownames(corr) == "riskpref.prodrisk."] <- "Production risk preferences"
rownames(corr)[rownames(corr) == "riskpref.markrisk."] <- "Market risk preferences"
rownames(corr)[rownames(corr) == "riskpref.plantrisk."] <- "Plant protection risk preferences"
rownames(corr)[rownames(corr) == "noncog.SelfHarvest."] <- "Self-efficacy"
rownames(corr)[rownames(corr) == "noncog.LocusSkills."] <- "Locus of control"
rownames(corr)[rownames(corr) == "noncog.ambitious."] <- "Ambition"
rownames(corr)[rownames(corr) == "wine_regionTicino"] <- "Region Ticino"
rownames(corr)[rownames(corr) == "wine_regionValais"] <- "Region Valais"
rownames(corr)[rownames(corr) == "wine_regionVaud"] <- "Region Vaud"
rownames(corr)[rownames(corr) == "wine_regionTrois lacs"] <- "Region Trois lacs"
rownames(corr)[rownames(corr) == "wine_regionDeutschschweiz"] <- "Region Deutschschweiz"
rownames(corr)[rownames(corr) == "wine_regionGeneva"] <- "Region Geneva"

Figure_D1 <- ggcorrplot(corr, hc.order = FALSE, legend.title = "Pearson\ncorrelation",
           p.mat = p.mat, insig = "blank", lab = TRUE, lab_size = 0.75,
           outline.color = "grey") +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_blank(),
        axis.text.x = element_text(size = 4, angle = 90, vjust = 0.5, hjust=1),
        axis.text.y = element_text(size = 4)) 

Figure_D1

ggsave(Figure_D1, file = "Appendix_Figure_D1.png", 
       width = 40, height = 20, dpi = 600, units = "cm", bg = "white")
```

## Figure D2: Variance inflation factors

```{r FigureD2, results = 'asis', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE, fig.height=10, out.width="100%"}
vif_data <- regression_data

vif_data$`wine_regionTrois lacs` <- ifelse(vif_data$wine_region == "Trois lacs", 1, 0)
vif_data$wine_regionTicino <- ifelse(vif_data$wine_region == "Ticino", 1, 0)
vif_data$wine_regionVaud <- ifelse(vif_data$wine_region == "Vaud", 1, 0)
vif_data$wine_regionValais <- ifelse(vif_data$wine_region == "Valais", 1, 0)
vif_data$wine_regionDeutschschweiz <- ifelse(vif_data$wine_region == "Deutschschweiz", 1, 0)
vif_data$wine_regionGeneva <- ifelse(vif_data$`wine_regionTrois lacs` != 1 & vif_data$wine_regionTicino != 1 & vif_data$wine_regionVaud != 1 &
                                       vif_data$wine_regionValais != 1 & vif_data$wine_regionDeutschschweiz != 1, 1, 0)
vif_data$wine_region <- NULL

### Compute variance inflation factor (Pre)
m_vif_pre <- lm(formula = change_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + 
           labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate +
           avg_oidium + NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + 
           FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. +
           timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + 
           noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + 
             wine_regionTicino + wine_regionVaud + wine_regionValais + wine_regionGeneva +
             `wine_regionTrois lacs`, data = vif_data)

vif_values <- data.frame(vif(m_vif_pre))
vif_values$names <- row.names(vif_values)
names(vif_values)[1] <- "vif"

# Renaming
vif_values$category <- ""
vif_values$category[vif_values$names == "labor"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "age"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "female"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "farmsize"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "earning_farming"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "earning_viticulture"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "AOC"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "labels.Org."] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "labels.Demeter."] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "labels.IPSuisse."] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "direct_marketing"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "retail"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "education1.A7."] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "FRGknowledge.SQ001."] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "ReplantRate"] <- "Farmer- and farm\ncharacteristics"
vif_values$category[vif_values$names == "successor_var"] <- "Farmer- and farm\ncharacteristics"

vif_values$category[vif_values$names == "avg_oidium"] <- "Regional\ncharacteristics"
vif_values$category[vif_values$names == "wine_regionDeutschschweiz"] <- "Regional\ncharacteristics"
vif_values$category[vif_values$names == "wine_regionTicino"] <- "Regional\ncharacteristics"
vif_values$category[vif_values$names == "wine_regionValais"] <- "Regional\ncharacteristics"
vif_values$category[vif_values$names == "wine_regionVaud"] <- "Regional\ncharacteristics"
vif_values$category[vif_values$names == "wine_regionTicino"] <- "Regional\ncharacteristics"
vif_values$category[vif_values$names == "`wine_regionTrois lacs`"] <- "Regional\ncharacteristics"
vif_values$category[grep("Gen", vif_values$names)] <- "Regional\ncharacteristics"

vif_values$category[vif_values$names == "NegImpact.A2."] <- "Perceptions"
vif_values$category[vif_values$names == "FRGprecp.FRGhealth."] <- "Perceptions"
vif_values$category[vif_values$names == "FRGprecp.FRGenv."] <- "Perceptions"
vif_values$category[vif_values$names == "FRGprecp.FRGfuture."] <- "Perceptions"
vif_values$category[vif_values$names == "FRGprecp.FRGmarket."] <- "Perceptions"
vif_values$category[vif_values$names == "FRGprecp.FRGwtp."] <- "Perceptions"
vif_values$category[vif_values$names == "FRGprecp.FRGqual."] <- "Perceptions"
vif_values$category[vif_values$names == "outlook.A5."] <- "Perceptions"

vif_values$category[vif_values$names == "timepref.timep."] <- "Preferences"
vif_values$category[vif_values$names == "riskpref.prodrisk."] <- "Preferences"
vif_values$category[vif_values$names == "riskpref.markrisk."] <- "Preferences"
vif_values$category[vif_values$names == "riskpref.plantrisk."] <- "Preferences"

vif_values$category[vif_values$names == "noncog.SelfHarvest."] <- "Personality\ntraits"
vif_values$category[vif_values$names == "noncog.LocusSkills."] <- "Personality\ntraits"
vif_values$category[vif_values$names == "noncog.ambitious."] <- "Personality\ntraits"

vif_values$names[vif_values$names == "labor"] <- "Labour"
vif_values$names[vif_values$names == "age"] <- "Age"
vif_values$names[vif_values$names == "female"] <- "Female"
vif_values$names[vif_values$names == "farmsize"] <- "Farm size"
vif_values$names[vif_values$names == "earning_farming"] <- "Farming specialization"  
vif_values$names[vif_values$names == "earning_viticulture"] <- "Viticulture specialization"
vif_values$names[vif_values$names == "AOC"] <- "Geographical denomination label"
vif_values$names[vif_values$names == "labels.Org."] <- "Organic label"
vif_values$names[vif_values$names == "labels.Demeter."] <- "Bio-dynamic label"
vif_values$names[vif_values$names == "labels.IPSuisse."] <- "Integrated production label"
vif_values$names[vif_values$names == "direct_marketing"] <- "Direct marketing"
vif_values$names[vif_values$names == "retail"] <- "Marketing to retail"
vif_values$names[vif_values$names == "education1.A7."] <- "Further education"
vif_values$names[vif_values$names == "FRGknowledge.SQ001."] <- "Knowledge about FRG"
vif_values$names[vif_values$names == "ReplantRate"] <- "Replantation rate"
vif_values$names[vif_values$names == "successor_var"] <- "Farm successor"
vif_values$names[vif_values$names == "avg_oidium"] <- "Oidium infection risk"
vif_values$names[vif_values$names == "NegImpact.A2."] <- "Fungal damage"
vif_values$names[vif_values$names == "FRGprecp.FRGhealth."] <- "FRG have a positive impact on the human health\nof farmers and communities surrounding farms"
vif_values$names[vif_values$names == "FRGprecp.FRGenv."] <- "FRG varieties are better for the environment"
vif_values$names[vif_values$names == "FRGprecp.FRGfuture."] <- "FRG wine use will increase in the future"
vif_values$names[vif_values$names == "FRGprecp.FRGmarket."] <- "Wine from FRG is difficult to market"
vif_values$names[vif_values$names == "FRGprecp.FRGwtp."] <- "Consumers are willing to pay less for wine from FRG"
vif_values$names[vif_values$names == "FRGprecp.FRGqual."] <- "Wine from FRG is of lower quality\nthan traditional varieties"
vif_values$names[vif_values$names == "outlook.A5."] <- "Banned copper"
vif_values$names[vif_values$names == "timepref.timep."] <- "Time preferences"
vif_values$names[vif_values$names == "riskpref.prodrisk."] <- "Production risk preferences"
vif_values$names[vif_values$names == "riskpref.markrisk."] <- "Market risk preferences"
vif_values$names[vif_values$names == "riskpref.plantrisk."] <- "Plant protection risk preferences"
vif_values$names[vif_values$names == "noncog.SelfHarvest."] <- "Self-efficacy"
vif_values$names[vif_values$names == "noncog.LocusSkills."] <- "Locus of control"
vif_values$names[vif_values$names == "noncog.ambitious."] <- "Ambition"
vif_values$names[vif_values$names == "wine_regionTicino"] <- "Wine region Ticino"
vif_values$names[vif_values$names == "wine_regionVaud"] <- "Wine region Vaud"
vif_values$names[vif_values$names == "wine_regionValais"] <- "Wine region Valais"
vif_values$names[vif_values$names == "wine_regionGeneva"] <- "Wine region Geneva"
vif_values$names[vif_values$names == "wine_regionDeutschschweiz"] <- "Wine region Deutschschweiz"
vif_values$names[vif_values$names == "`wine_regionTrois lacs`"] <- "Wine region Trois Lacs"

Figure_D2 <- ggplot(vif_values, aes(x = reorder(names, vif), y = vif)) +
  geom_hline(yintercept = 5, color = "red", size = 1, alpha = 0.5) +
  geom_col(position = position_dodge(0.8), width = 0.8) + 
  coord_flip() +
  theme_minimal() +
  theme(axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 10, l = 0)),
        panel.grid.major.y = element_blank(),
        strip.placement = "outside",
        strip.background = element_rect(fill=NA,colour="black"),
        strip.text.y = element_text(size = 7, face = "bold", colour = "black"),
        axis.text.y = element_text(size = 6),
        panel.spacing=unit(0,"cm"),
        legend.position = "top") +
  ylab("Variance inflation factors") +
  facet_grid(category ~ ., space = "free", scales="free", switch="y") +
  scale_y_continuous(limits = c(0,6), breaks = c(0,1,2,3,4,5,6),labels = c("0","1","2","3","4","5","6"),
                     expand = c(0, 0)) +
  geom_text(
    aes(x = names, y = vif, label = round(vif,2)), 
    hjust = -0.5, size = 2,
    position = position_dodge(width = 1),
    inherit.aes = TRUE) +  
  xlab("")

Figure_D2

ggsave(Figure_D2, file = "Appendix_Figure_D2.png", 
       width = 30, height = 30, dpi = 600, units = "cm", bg = "white")
```

## Table D2: Separate inclusion of preferences and perceptions

```{r TableD2, results = 'hide', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
### Removing some critical variables
models_rcr <- list(
  m1 <- lm(formula = change_share_piwi ~ NegImpact.A2. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m2 <- lm(formula = change_share_piwi ~ FRGprecp.FRGhealth. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing +  education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m3 <- lm(formula = change_share_piwi ~ FRGprecp.FRGenv. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m4 <- lm(formula = change_share_piwi ~ FRGprecp.FRGfuture. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m5 <- lm(formula = change_share_piwi ~ FRGprecp.FRGmarket. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m6 <- lm(formula = change_share_piwi ~ FRGprecp.FRGwtp. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m7 <- lm(formula = change_share_piwi ~ FRGprecp.FRGqual. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m8 <- lm(formula = change_share_piwi ~ outlook.A5. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m9 <- lm(formula = change_share_piwi ~ timepref.timep. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m10 <- lm(formula = change_share_piwi ~ riskpref.prodrisk. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m11 <- lm(formula = change_share_piwi ~ riskpref.markrisk. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m12 <- lm(formula = change_share_piwi ~ riskpref.plantrisk. + labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data)
)

clwb <- list(
  se1 <- cluster.boot(models_rcr[[1]], regression_data$wine_region, boot_type = "wild"),
  se2 <- cluster.boot(models_rcr[[2]], regression_data$wine_region, boot_type = "wild"),
  se3 <- cluster.boot(models_rcr[[3]], regression_data$wine_region, boot_type = "wild"),
  se4 <- cluster.boot(models_rcr[[4]], regression_data$wine_region, boot_type = "wild"),
  se5 <- cluster.boot(models_rcr[[5]], regression_data$wine_region, boot_type = "wild"),
  se6 <- cluster.boot(models_rcr[[6]], regression_data$wine_region, boot_type = "wild"),
  se7 <- cluster.boot(models_rcr[[7]], regression_data$wine_region, boot_type = "wild"),
  se8 <- cluster.boot(models_rcr[[8]], regression_data$wine_region, boot_type = "wild"),
  se9 <- cluster.boot(models_rcr[[9]], regression_data$wine_region, boot_type = "wild"),
  se10 <- cluster.boot(models_rcr[[10]], regression_data$wine_region, boot_type = "wild"),
  se11 <- cluster.boot(models_rcr[[11]], regression_data$wine_region, boot_type = "wild"),
  se12 <- cluster.boot(models_rcr[[12]], regression_data$wine_region, boot_type = "wild")
)

ct <- list(
  ct1 <- coeftest(models_rcr[[1]], clwb[[1]])[, 2],
  ct2 <- coeftest(models_rcr[[2]], clwb[[2]])[, 2],
  ct3 <- coeftest(models_rcr[[3]], clwb[[3]])[, 2],
  ct4 <- coeftest(models_rcr[[4]], clwb[[4]])[, 2],
  ct5 <- coeftest(models_rcr[[5]], clwb[[5]])[, 2],
  ct6 <- coeftest(models_rcr[[6]], clwb[[6]])[, 2],
  ct7 <- coeftest(models_rcr[[7]], clwb[[7]])[, 2],
  ct8 <- coeftest(models_rcr[[8]], clwb[[8]])[, 2],
  ct9 <- coeftest(models_rcr[[9]], clwb[[9]])[, 2],
  ct10 <- coeftest(models_rcr[[10]], clwb[[10]])[, 2],
  ct11 <- coeftest(models_rcr[[11]], clwb[[11]])[, 2],
  ct12 <- coeftest(models_rcr[[12]], clwb[[12]])[, 2]
)

stargazer(c(models_rcr),
          se = c(ct),
          title="OLS Results", 
          dep.var.labels=c("Change in share of land devoted to fungus-resistant varieties (%)"),
          covariate.labels=c("Fungal damage","FRG have a positive impact on the human health of farmers and communities surrounding farms","FRG varieties are better for the environment","FRG wine use will increase in the future","Wine from FRG is difficult to market","Consumers are willing to pay less for wine from FRG","Wine from FRG is of lower quality than traditional varieties","Banned copper","Time preferences","Production risk preferences","Market risk preferences","Plant protection risk preferences"), 
          omit.stat=c("LL","ser","f"), 
          no.space=FALSE,
          align=TRUE,
          single.row = TRUE,
          omit = c('[w][i][n][e][_][r][e][g][i][o][n]','[l][a][b][o][r]','[a][g][e]',
                   '[f][e][m][a][l][e]','[f][a][r][m][s][i][z][e]',
                   '[e][a][r][n][i][n][g][_][f][a][r][m][i][n][g]',
                   '[e][a][r][n][i][n][g][_][v][i][t][i][c][u][l][t][u][r][e]',
                   '[A][O][C]','[l][a][b][e][l][s][.][O][r][g][.]',
                   '[l][a][b][e][l][s][.][D][e][m][e][t][e][r][.]',
                   '[l][a][b][e][l][s][.][I][P][S][u][i][s][s][e][.]',
                   '[d][i][r][e][c][t][_][m][a][r][k][e][t][i][n][g]',
                   '[e][d][u][c][a][t][i][o][n][1][.][A][7][.]',
                   '[F][R][G][k][n][o][w][l][e][d][g][e][.][S][Q][0][0][1][.]',
                   '[s][u][c][c][e][s][s][o][r][_][v][a][r]',
                   '[R][e][p][l][a][n][t][R][a][t][e]','[n][o][n][c]'),
          add.lines=list(c('Wine region dummies', 'Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes'),
                         c('Controls', 'Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes','Yes')),
          notes.align = "l",
          style = "qje",
          notes.append = TRUE,
          column.sep.width = "-25pt",
          notes = "Clustered and wild bootstrapped standard errors at the wine region are shown in parentheses.",
          type='html',
          font.size = "tiny",
          star.char = c("","**", "***"), star.cutoffs = c(0.1, 0.05, 0.01),
          out="Appendix_Table_D2.doc")
```

## Table D3: LASSO regression output

```{r TableD3, results = 'hide', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
### LASSO regression output
sc_dataset <- regression_data %>%
  select(change_share_piwi, labor, age, earning_farming, earning_viticulture, AOC, 
         labels.Org., labels.Demeter., labels.IPSuisse., direct_marketing, education1.A7., FRGknowledge.SQ001., ReplantRate, successor_var,
         avg_oidium, NegImpact.A2., FRGprecp.FRGhealth., FRGprecp.FRGenv., FRGprecp.FRGfuture., FRGprecp.FRGmarket., 
         FRGprecp.FRGwtp., FRGprecp.FRGqual., 
         timepref.timep., riskpref.prodrisk., riskpref.markrisk., riskpref.plantrisk., 
         noncog.SelfHarvest., noncog.LocusSkills., noncog.ambitious., wine_region) %>%
  drop_na()

X <- sc_dataset %>%
  select(-change_share_piwi, -wine_region) %>% 
  as.matrix()

y <- sc_dataset %>%
  select(change_share_piwi) %>%
  as.matrix()

# before standardization
colMeans(X)    
apply(X,2,sd)  

# scale : mean = 0, std=1
X = scale(X)
y = scale(y)

# after standardization
colMeans(X)    
apply(X,2,sd)  

# Run cross-validation & select lambda
mod_cv <- cv.glmnet(x=X, y=y, family="gaussian",
                    intercept = F, alpha=1)
round(coef(mod_cv, c(mod_cv$lambda.min)),2)
```

## Figures E1 and E2: Regression results for current and expected uptake intensities (\%)

```{r FigureE2, results = 'asis', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
### Current and expected uptake intensities
#### Current uptake
models_current <- list(
  m1 <- lm(formula = share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC +
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + 
             education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + wine_region, data = data),
  m2 <- lm(formula = share_piwi ~ wine_region, data = data),
  m3 <- lm(formula = share_piwi ~ NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + 
             FRGprecp.FRGmarket. + FRGprecp.FRGwtp. +FRGprecp.FRGqual. + outlook.A5. + wine_region, data = data),
  m4 <- lm(formula = share_piwi ~ timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + wine_region, data = data),
  m5 <- lm(formula = share_piwi ~ noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = data),
  m6 <- lm(formula = share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + 
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate +
             NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + 
             FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. +
             timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + 
             noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = data)
)

### Adj. R-squared

# Farmer- and farm characteristics
summary(models_current[[1]])$adj.r.squared

# Regional characteristics
summary(models_current[[2]])$adj.r.squared

# Perceptions
summary(models_current[[3]])$adj.r.squared

# Preferences
summary(models_current[[4]])$adj.r.squared

# Personality
summary(models_current[[5]])$adj.r.squared

# Total
summary(models_current[[6]])$adj.r.squared


### Regression table
clwb_current <- list(
  se1 <- cluster.boot(models_current[[1]], data$wine_region, boot_type = "wild"),
  se2 <- cluster.boot(models_current[[2]], data$wine_region, boot_type = "wild"),
  se3 <- cluster.boot(models_current[[3]], data$wine_region, boot_type = "wild"),
  se4 <- cluster.boot(models_current[[4]], data$wine_region, boot_type = "wild"),
  se5 <- cluster.boot(models_current[[5]], data$wine_region, boot_type = "wild"),
  se6 <- cluster.boot(models_current[[6]], data$wine_region, boot_type = "wild")
)

ct_current <- list(
  ct1 <- coeftest(models_current[[1]], clwb_current[[1]])[, 2],
  ct2 <- coeftest(models_current[[2]], clwb_current[[2]])[, 2],
  ct3 <- coeftest(models_current[[3]], clwb_current[[3]])[, 2],
  ct4 <- coeftest(models_current[[4]], clwb_current[[4]])[, 2],
  ct5 <- coeftest(models_current[[5]], clwb_current[[5]])[, 2],
  ct6 <- coeftest(models_current[[6]], clwb_current[[6]])[, 2]
)

#### Future uptake
models_expected <- list(
  m1 <- lm(formula = expected_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC +
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + 
             education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + wine_region, data = regression_data),
  m2 <- lm(formula = expected_share_piwi ~ wine_region, data = regression_data),
  m3 <- lm(formula = expected_share_piwi ~ NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + 
             FRGprecp.FRGmarket. + FRGprecp.FRGwtp. +FRGprecp.FRGqual. + outlook.A5. + wine_region, data = regression_data),
  m4 <- lm(formula = expected_share_piwi ~ timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + wine_region, data = regression_data),
  m5 <- lm(formula = expected_share_piwi ~ noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data),
  m6 <- lm(formula = expected_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + 
             labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate +
             NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + 
             FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. +
             timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + 
             noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + wine_region, data = regression_data)
)

### Adj. R-squared

# Farmer- and farm characteristics
summary(models_expected[[1]])$adj.r.squared

# Regional characteristics
summary(models_expected[[2]])$adj.r.squared

# Perceptions
summary(models_expected[[3]])$adj.r.squared

# Preferences
summary(models_expected[[4]])$adj.r.squared

# Personality
summary(models_expected[[5]])$adj.r.squared

# Total
summary(models_expected[[6]])$adj.r.squared

### Regression table
clwb_expected <- list(
  se1 <- cluster.boot(models_expected[[1]], regression_data$wine_region, boot_type = "wild"),
  se2 <- cluster.boot(models_expected[[2]], regression_data$wine_region, boot_type = "wild"),
  se3 <- cluster.boot(models_expected[[3]], regression_data$wine_region, boot_type = "wild"),
  se4 <- cluster.boot(models_expected[[4]], regression_data$wine_region, boot_type = "wild"),
  se5 <- cluster.boot(models_expected[[5]], regression_data$wine_region, boot_type = "wild"),
  se6 <- cluster.boot(models_expected[[6]], regression_data$wine_region, boot_type = "wild")
)

ct_expected <- list(
  ct1 <- coeftest(models_expected[[1]], clwb_expected[[1]])[, 2],
  ct2 <- coeftest(models_expected[[2]], clwb_expected[[2]])[, 2],
  ct3 <- coeftest(models_expected[[3]], clwb_expected[[3]])[, 2],
  ct4 <- coeftest(models_expected[[4]], clwb_expected[[4]])[, 2],
  ct5 <- coeftest(models_expected[[5]], clwb_expected[[5]])[, 2],
  ct6 <- coeftest(models_expected[[6]], clwb_expected[[6]])[, 2]
)

# Adjusted R-squred plot for current and expected uptake
r_squared <- data.frame(name = c("Farmer- and\nfarm characteristics","Regional characteristics","Perceptions",
                                 "Preferences","Personality traits"), 
                        expected_ar2 = c(summary(models_expected[[1]])$adj.r.squared,
                                         summary(models_expected[[2]])$adj.r.squared,
                                         summary(models_expected[[3]])$adj.r.squared,
                                         summary(models_expected[[4]])$adj.r.squared,
                                         summary(models_expected[[5]])$adj.r.squared), 
                        current_ar2 = c(summary(models_current[[1]])$adj.r.squared,
                                        summary(models_current[[2]])$adj.r.squared,
                                        summary(models_current[[3]])$adj.r.squared,
                                        summary(models_current[[4]])$adj.r.squared,
                                        summary(models_current[[5]])$adj.r.squared))

r_squared_long <- r_squared %>%
  gather(type, value, -name)

Figure_E2 <- ggplot(r_squared_long) + 
  geom_bar(
    aes(x = reorder(name, value), y = value, fill = factor(type), group = type), 
    stat='identity', position = 'dodge', width = 0.3) +
  geom_text(
    aes(x = name, y = value, label = round(value,3), group = type), 
    hjust = -0.5, size = 2.5,
    position = position_dodge(width = 0.3),
    inherit.aes = TRUE) + 
  theme_minimal() +
  theme(panel.grid.major.y = element_blank(),
        strip.text.y = element_text(size = 10, face = "bold", colour = "black"),
        axis.text.y = element_text(size = 10),
        axis.title.y = element_text(margin = margin(t = 0, r = 0, b = 0, l = 30)),
        legend.position = "top",
        legend.title=element_text(size = 10),
        legend.text=element_text(size = 9)) +
  xlab("") +
  ylab("Adjusted R-squared") +
  scale_y_continuous(limits = c(0,0.40), breaks = c(0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4)) +
  scale_fill_manual(name = "Dependent variable", values = c("turquoise4","#ed980c"), 
                    labels = c("Current uptake intensity (%)","Expected uptake intensity in ten years (%)")) +
  coord_flip() 

Figure_E2

ggsave(Figure_E2, file = "Appendix_Figure_E2.png", 
       width = 40, height = 20, dpi = 600, units = "cm", bg = "white")
```

```{r FigureE1, include = TRUE, results = 'asis', echo = TRUE, message = FALSE, warning = FALSE, fig.height=10, out.width="100%"}
### Coefficient plot current and expected share
#### Current
model_output_current <- tidy(models_current[[6]])
out_conf_current <- tidy(models_current[[6]], conf.int = TRUE)
lm_model_out_current <- round_df(out_conf_current, digits=3)
lm_model_out_current <- lm_model_out_current[-1,] #remove the intercept 
names(lm_model_out_current)[names(lm_model_out_current) == "term"] <- "factor"

clustered_se_current <- as.data.frame(ct_current[[6]]) 
names(clustered_se_current)[1] <- "ct6"
clustered_se_current$factor <- row.names(clustered_se_current)
clustered_se_current <- clustered_se_current %>%
  filter(factor != "(Intercept)")

#### Expected
model_output_expected <- tidy(models_expected[[6]])
out_conf_expected <- tidy(models_expected[[6]], conf.int = TRUE)
lm_model_out_expected <- round_df(out_conf_expected, digits=3)
lm_model_out_expected <- lm_model_out_expected[-1,] #remove the intercept 
names(lm_model_out_expected)[names(lm_model_out_expected) == "term"] <- "factor"

clustered_se_expected <- as.data.frame(ct_expected[[6]]) 
names(clustered_se_expected)[1] <- "ct6"
clustered_se_expected$factor <- row.names(clustered_se_expected)
clustered_se_expected <- clustered_se_expected %>%
  filter(factor != "(Intercept)")

# Merge
lm_model_out <- merge(lm_model_out_current, clustered_se_current, by = "factor")
lm_model_out$CI95_new <- lm_model_out$ct6*3.92
lm_model_out$CI99_new <- lm_model_out$ct6*5.15
lm_model_out$CI95_new_upper <- lm_model_out$estimate+(lm_model_out$CI95_new/2)
lm_model_out$CI95_new_lower <- lm_model_out$estimate-(lm_model_out$CI95_new/2)
lm_model_out$CI99_new_upper <- lm_model_out$estimate+(lm_model_out$CI99_new/2)
lm_model_out$CI99_new_lower <- lm_model_out$estimate-(lm_model_out$CI99_new/2)
lm_model_out <- lm_model_out %>%
  select(factor, estimate, CI95_new_upper, CI95_new_lower, CI99_new_upper, CI99_new_lower) %>%
  mutate(model = "current")

lm_model_out_expected <- merge(lm_model_out_expected, clustered_se_expected, by = "factor")
lm_model_out_expected$CI95_new <- lm_model_out_expected$ct6*3.92
lm_model_out_expected$CI99_new <- lm_model_out_expected$ct6*5.15
lm_model_out_expected$CI95_new_upper <- lm_model_out_expected$estimate+(lm_model_out_expected$CI95_new/2)
lm_model_out_expected$CI95_new_lower <- lm_model_out_expected$estimate-(lm_model_out_expected$CI95_new/2)
lm_model_out_expected$CI99_new_upper <- lm_model_out_expected$estimate+(lm_model_out_expected$CI99_new/2)
lm_model_out_expected$CI99_new_lower <- lm_model_out_expected$estimate-(lm_model_out_expected$CI99_new/2)

lm_model_out_expected <- lm_model_out_expected %>%
  select(factor, estimate, CI95_new_upper, CI95_new_lower, CI99_new_upper, CI99_new_lower) %>%
  mutate(model = "expected")

lm_model_out <- rbind(lm_model_out, lm_model_out_expected)

# Categorizing
lm_model_out$category <- ""
lm_model_out$category[lm_model_out$factor == "labor"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "age"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "female"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "farmsize"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "earning_farming"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "earning_viticulture"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "AOC"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "labels.Org."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "labels.Demeter."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "labels.IPSuisse."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "direct_marketing"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "retail"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "education1.A7."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "FRGknowledge.SQ001."] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "ReplantRate"] <- "Farmer- and farm\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "successor_var"] <- "Farmer- and farm\ncharacteristics"

lm_model_out$category[lm_model_out$factor == "avg_oidium"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_region"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionTicino"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionValais"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionVaud"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionTicino"] <- "Regional\ncharacteristics"
lm_model_out$category[lm_model_out$factor == "wine_regionTrois lacs"] <- "Regional\ncharacteristics"
lm_model_out$category[grep("Gen", lm_model_out$factor)] <- "Regional\ncharacteristics"

lm_model_out$category[lm_model_out$factor == "NegImpact.A2."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGhealth."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGenv."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGfuture."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGmarket."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGwtp."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "FRGprecp.FRGqual."] <- "Perceptions"
lm_model_out$category[lm_model_out$factor == "outlook.A5."] <- "Perceptions"

lm_model_out$category[lm_model_out$factor == "timepref.timep."] <- "Preferences"
lm_model_out$category[lm_model_out$factor == "riskpref.prodrisk."] <- "Preferences"
lm_model_out$category[lm_model_out$factor == "riskpref.markrisk."] <- "Preferences"
lm_model_out$category[lm_model_out$factor == "riskpref.plantrisk."] <- "Preferences"

lm_model_out$category[lm_model_out$factor == "noncog.SelfHarvest."] <- "Personality\ntraits"
lm_model_out$category[lm_model_out$factor == "noncog.LocusSkills."] <- "Personality\ntraits"
lm_model_out$category[lm_model_out$factor == "noncog.ambitious."] <- "Personality\ntraits"

# Renaming
lm_model_out$factor[lm_model_out$factor == "labor"] <- "Labour"
lm_model_out$factor[lm_model_out$factor == "age"] <- "Age"
lm_model_out$factor[lm_model_out$factor == "female"] <- "Female"
lm_model_out$factor[lm_model_out$factor == "farmsize"] <- "Farmsize"
lm_model_out$factor[lm_model_out$factor == "earning_farming"] <- "Farming specialization"  
lm_model_out$factor[lm_model_out$factor == "earning_viticulture"] <- "Viticulture specialization"
lm_model_out$factor[lm_model_out$factor == "AOC"] <- "Geographical denomination label"
lm_model_out$factor[lm_model_out$factor == "labels.Org."] <- "Organic label"
lm_model_out$factor[lm_model_out$factor == "labels.Demeter."] <- "Bio-dynamic label"
lm_model_out$factor[lm_model_out$factor == "labels.IPSuisse."] <- "Integrated production label"
lm_model_out$factor[lm_model_out$factor == "direct_marketing"] <- "Direct marketing"
lm_model_out$factor[lm_model_out$factor == "retail"] <- "Marketing to retail"
lm_model_out$factor[lm_model_out$factor == "education1.A7."] <- "Further education"
lm_model_out$factor[lm_model_out$factor == "FRGknowledge.SQ001."] <- "Knowledge about FRG"
lm_model_out$factor[lm_model_out$factor == "ReplantRate"] <- "Replantation rate"
lm_model_out$factor[lm_model_out$factor == "successor_var"] <- "Farm successor"
lm_model_out$factor[lm_model_out$factor == "avg_oidium"] <- "Oidium infection risk"
lm_model_out$factor[lm_model_out$factor == "NegImpact.A2."] <- "Fungal damage"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGhealth."] <- "FRG have a positive impact on the human health\nof farmers and communities surrounding farms"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGenv."] <- "FRG varieties are better for the environment"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGfuture."] <- "FRG wine use will increase in the future"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGmarket."] <- "Wine from FRG is difficult to market"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGwtp."] <- "Consumers are willing to pay less for wine from FRG"
lm_model_out$factor[lm_model_out$factor == "FRGprecp.FRGqual."] <- "Wine from FRG is of lower quality\nthan traditional varieties"
lm_model_out$factor[lm_model_out$factor == "outlook.A5."] <- "Banned copper"
lm_model_out$factor[lm_model_out$factor == "timepref.timep."] <- "Time preferences"
lm_model_out$factor[lm_model_out$factor == "riskpref.prodrisk."] <- "Production risk preferences"
lm_model_out$factor[lm_model_out$factor == "riskpref.markrisk."] <- "Market risk preferences"
lm_model_out$factor[lm_model_out$factor == "riskpref.plantrisk."] <- "Plant protection risk preferences"
lm_model_out$factor[lm_model_out$factor == "noncog.SelfHarvest."] <- "Self-efficacy"
lm_model_out$factor[lm_model_out$factor == "noncog.LocusSkills."] <- "Locus of control"
lm_model_out$factor[lm_model_out$factor == "noncog.ambitious."] <- "Ambition"
lm_model_out$factor[lm_model_out$factor == "wine_regionTicino"] <- "Region Ticino"
lm_model_out$factor[lm_model_out$factor == "wine_regionValais"] <- "Region Valais"
lm_model_out$factor[lm_model_out$factor == "wine_regionVaud"] <- "Region Vaud"
lm_model_out$factor[lm_model_out$factor == "wine_regionTrois lacs"] <- "Region Trois lacs"
lm_model_out$factor[grep("Gen", lm_model_out$factor)] <- "Region Geneva"

lm_model_out$sig_estimate <- ifelse(sign(lm_model_out$CI95_new_lower) == sign(lm_model_out$CI95_new_upper), as.character(round(lm_model_out$estimate,3)),"")

# Now plot them
Figure_E1 <- ggplot(data = lm_model_out, aes(x = reorder(factor, estimate), y = estimate,
                                             color = model)) +
  geom_hline(yintercept = 0, color = "red", size = 1, alpha = 0.5) +
  geom_linerange(aes(x=reorder(factor, estimate), 
                     ymin = CI95_new_lower,
                     ymax = CI95_new_upper),
                 alpha = 0.8, size = 1, position = position_dodge(width = 1/2)) + 
  geom_linerange(aes(x=reorder(factor, estimate), 
                     ymin = CI99_new_lower,
                     ymax = CI99_new_upper),
                 alpha = 0.4, size = 1, position = position_dodge(width = 1/2)) +
  geom_point(aes(x=reorder(factor, estimate), y=estimate), position = position_dodge(width = 0.5), 
             show.legend = T) + 
  geom_text(aes(x=factor, y=estimate, label=sig_estimate), position = position_dodge(width = 0.75),
            show.legend = F, size = 2.5, vjust = -0.5) +
  xlab("") +
  ylab("Coefficient estimates (and 99%/95% confidence intervals)") +
  facet_grid(category ~ ., space = "free", scales="free", switch="y") +
  coord_flip() +
  theme_minimal() +
  theme(axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 10, l = 0)),
        panel.grid.major.y = element_blank(),
        strip.placement = "outside",
        strip.background = element_rect(fill=NA,colour="black"),
        strip.text.y = element_text(size=10, face = "bold", colour = "black"),
        axis.text.y = element_text(size = 11),
        panel.spacing=unit(0,"cm"),
        legend.position = "top") +
  scale_color_manual(name = "Dependent variable:", values = c("turquoise4","#ed980c"),
                     labels = c("Current share under FRG","Expected share under FRG"))

Figure_E1

ggsave(Figure_E1, file = "Appendix_Figure_E1.png", 
       width = 30, height = 30, units = "cm", dpi = 600, bg = "white")
```

## Table F1: Current and expected share per production system
This figure is not reproduced here.

## Figure G1: Change in the expected land share and uncertainty

```{r FigureG1, results = 'asis', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
# Change in uncertainty and expected value
Figure_G1 <- ggplot(data = data, aes(y = change_share_piwi, x = variance_share_piwi)) +
  geom_hline(yintercept = 0, color = "red", size = 1, alpha = 0.5) +
  geom_jitter(position = position_jitter(0.2), alpha = 0.5, size = 1.8, color = "grey50") +
  theme_minimal() +
  xlab("Variance of the triangular share distribution") +
  ylab(expression(symbol('\254') * " decrease    " * symbol('\104') * " land share (pp)" * "    increase " * symbol('\256'))) +
  scale_y_continuous(breaks = c(-100,-50,0,50,100), labels = c("-100","-50","0","50","100"), limits = c(-100,100)) +
  scale_x_continuous(breaks = c(0,100,200,300,400,500,600), 
                     labels = c("0","100","200","300","400","500","600")) +
  coord_cartesian(xlim = c(0,600)) +
  theme(panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank(),
        text = element_text(size = 16)) 

Figure_G1

ggsave(Figure_G1, file = "Appendix_Table_G1.png", 
       width = 30, height = 15, units = "cm", bg = "white")
```

## Figure G2: Frequency distribution of the variance around the expected share

```{r FigureG2, results = 'asis', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
# Histogram around variance
Figure_G2 <- ggplot(data, aes(variance_share_piwi)) +  
  geom_histogram(bins = 30, fill = "grey50", color = "grey20") +
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank(),
        text = element_text(size = 16),
        axis.title.y = element_text(margin = margin(r = 0)),
        axis.text.y = element_text(margin = margin(r = 0))) +
  xlab("Variance of the triangular share distribution") +
  ylab("Count") + 
  scale_x_continuous(breaks = c(0,100,200,300,400,500,600), 
                     labels = c("0","100","200","300","400","500","600")) +
  coord_cartesian(xlim = c(0,600)) +
  scale_y_continuous(breaks = c(0,50,100,150,200,250))

Figure_G2

ggsave(Figure_G2, file = "Appendix_Table_G2.png", width = 35, height = 20, units = "cm", bg = "white")
```

## Table H1: Fungal pest pressure and the uptake of fungus-resistant varieties

```{r TableH1, results = 'hide', header = FALSE, tab.cap = FALSE, message = FALSE, warning = FALSE, echo = TRUE}
### Oidium index instead of regional dummy
models_oi <- list(
  m1 <- lm(formula = share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. + timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + avg_oidium, data = regression_data),
  m2 <- lm(formula = expected_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. + timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + avg_oidium, data = regression_data),
  m3 <- lm(formula = change_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. + timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + avg_oidium, data = regression_data),
  m4 <- lm(formula = share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. + timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + avg_peronospora, data = regression_data),
  m5 <- lm(formula = expected_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. + timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + avg_peronospora, data = regression_data),
  m6 <- lm(formula = change_share_piwi ~ labor + age + female + farmsize + earning_farming + earning_viticulture + AOC + labels.Org. + labels.Demeter. + labels.IPSuisse. + direct_marketing + education1.A7. + FRGknowledge.SQ001. + successor_var + ReplantRate + NegImpact.A2. + FRGprecp.FRGhealth. + FRGprecp.FRGenv. + FRGprecp.FRGfuture. + FRGprecp.FRGmarket. + FRGprecp.FRGwtp. + FRGprecp.FRGqual. + outlook.A5. + timepref.timep. + riskpref.prodrisk. + riskpref.markrisk. + riskpref.plantrisk. + noncog.SelfHarvest. + noncog.LocusSkills. + noncog.ambitious. + avg_peronospora, data = regression_data)
)

clwb_oi <- list(
  se1 <- cluster.boot(models_oi[[1]], regression_data$avg_oidium, boot_type = "wild"),
  se2 <- cluster.boot(models_oi[[2]], regression_data$avg_oidium, boot_type = "wild"),
  se3 <- cluster.boot(models_oi[[3]], regression_data$avg_oidium, boot_type = "wild"),
  se4 <- cluster.boot(models_oi[[1]], regression_data$avg_peronospora, boot_type = "wild"),
  se5 <- cluster.boot(models_oi[[2]], regression_data$avg_peronospora, boot_type = "wild"),
  se6 <- cluster.boot(models_oi[[3]], regression_data$avg_peronospora, boot_type = "wild")
)

ct_oi <- list(
  ct1 <- coeftest(models_oi[[1]], clwb_oi[[1]])[, 2],
  ct2 <- coeftest(models_oi[[2]], clwb_oi[[2]])[, 2],
  ct3 <- coeftest(models_oi[[3]], clwb_oi[[3]])[, 2],
  ct4 <- coeftest(models_oi[[4]], clwb_oi[[4]])[, 2],
  ct5 <- coeftest(models_oi[[5]], clwb_oi[[5]])[, 2],
  ct6 <- coeftest(models_oi[[6]], clwb_oi[[6]])[, 2]
)

stargazer(c(models_oi),
          se = c(ct_oi),
          title="OLS Results", 
          dep.var.labels=c("Current share of land devoted to fungus-resistant varieties (%)",
                           "Expected share of land devoted to fungus-resistant varieties in 10 years (%)",
                           "Change of the share of land devoted to fungus-resistant varieties (%)",
                           "Current share of land devoted to fungus-resistant varieties (%)",
                           "Expected share of land devoted to fungus-resistant varieties in 10 years (%)",
                           "Change of the share of land devoted to fungus-resistant varieties (%)"),
          covariate.labels=c("Oidium risk index","Peronospora Viticola risk index"), 
          omit.stat=c("LL","ser","f"), 
          no.space=FALSE,
          align=TRUE,
          single.row = FALSE,
          omit = c('labor', 'age', 'female', 'farmsize', 'earning_farming', 'earning_viticulture', 'AOC','labels.Org.','labels.Demeter.', 'labels.IPSuisse.', 'direct_marketing', 'education1.A7.', 'FRGknowledge.SQ001.','successor_var', 'ReplantRate','NegImpact.A2.', 'FRGprecp.FRGhealth.', 'FRGprecp.FRGenv.', 'FRGprecp.FRGfuture.', 'FRGprecp.FRGmarket.','FRGprecp.FRGwtp.', 'FRGprecp.FRGqual.', 'outlook.A5.','timepref.timep.', 'riskpref.prodrisk.', 'riskpref.markrisk.', 'riskpref.plantrisk.', 'noncog.SelfHarvest.','noncog.LocusSkills.', 'noncog.ambitious.'),
          add.lines=list(c('Wine region dummies', 'No','No','No','No','No','No'),
                         c('Controls','Yes','Yes','Yes','Yes','Yes','Yes')),
          notes.align = "l",
          style = "qje",
          notes.append = TRUE,
          column.sep.width = "-25pt",
          notes = "Clustered and wild bootstrapped standard errors at the wine region are shown in parentheses.",
          type='html',
          font.size = "tiny",
          out="Appendix_Table_H1.doc")
```