-
Notifications
You must be signed in to change notification settings - Fork 1
/
02_Prepare_FADN.R
116 lines (90 loc) · 4.37 KB
/
02_Prepare_FADN.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# ---------------------------------------------------------------------------- #
# #
# R code for the article: "A note on synthetic data for replication purposes #
# in agricultural economics" #
# #
# Authors: Stefan Wimmer and Robert Finger #
# #
# Corresponding author: Stefan Wimmer ([email protected]) #
# #
# Citation: Wimmer, S., Finger, R. (2023). "A note on synthetic data for #
# replication purposes in agricultural economics." Journal of Agricultural #
# Economics. #
# #
# This program prepares the FADN data for production function and frontier #
# estimation. The data (stored in the subfolder 'Data') are not publicly #
# available but can be requested from DG-Agri. The script was successfully #
# run with R version 4.2.0. #
# #
# ---------------------------------------------------------------------------- #
# Content:
# 0) Preparation (working directory, packages, data)
# 1) Generate output variable
# 2) Generate productive input variables
# 3) Make homogeneous sample
# 4) Save the sample
# -------------------- #
#### 0. Preparation ####
# -------------------- #
# Set working directory
my.wd <- getwd() # NOTE: getwd() can be replaced with any working directory
setwd(my.wd)
# Create subfolders for R output
dir.create(file.path("rOutput"))
# Install missing packages
list.of.packages <- c("dplyr")
new.packages <- list.of.packages[!(list.of.packages %in%
installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
# Load packages
library(dplyr) # for data management
# Load FADN data and keep crop farms only
dat <- read.csv("Data/DEU2018.csv") %>%
filter(TF8 == 1)
# -------------------------------------------- #
#### 1. Generate productive input variables ####
# -------------------------------------------- #
#------------------#
##### 1.1 Land #####
#------------------#
# Define land as total utilised agricultural area
dat$land <- dat$SE025
#-------------------#
##### 1.2 Labor #####
#-------------------#
# Define labor as the sum of unpaid and paid labor input
dat$labor <- dat$SE015 + dat$SE020
#----------------------#
##### 1.3 Material #####
#----------------------#
# Define material as variable costs
dat$material <- dat$SE285 + dat$SE295 + dat$SE300 + dat$SE305 + # crops related inputs until here
dat$SE310 + dat$SE320 + dat$SE330 + # livestock related inputs until here
dat$SE340 + dat$SE345 + dat$SE350 + dat$SE356 # other materials until here
#---------------------#
##### 1.4 Capital #####
#---------------------#
# Define capital stock as average farm capital (which excludes land)
dat$capstock <- dat$SE510
# --------------------------------- #
#### 2. Generate output variable ####
# --------------------------------- #
# Define output as the sum of all crop outputs
dat$output <- dat$SE140 + dat$SE145 + dat$SE150 + dat$SE155 +
dat$SE160 + dat$SE165 + dat$SE170 + dat$SE175 +
dat$SE180 + dat$SE185 + dat$SE190 + dat$SE195 +
dat$SE200
#note: this is "total crop output", i.e. revenues for cereals, protein,
# potatoes, sugar beet, oilseed, industrial crops, vegetables,
# fruit trees, citrus fruit, wine grapes, olives, forage crops,
# and other crop output
# Drop farms with non-positive crop output
dat <- dat %>%
filter(output > 0) # --> only one observation dropped
# ------------------------ #
#### 3. Save the sample ####
# ------------------------ #
save(dat, file="rOutput/FADN.Rds")
# --------------------------------------- #
# End of the script #
# --------------------------------------- #