-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.Rmd
143 lines (120 loc) · 4.11 KB
/
Test.Rmd
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
title: "GPT - Self Documenting Code Test"
author: "Avery Dobbins"
date: "`r Sys.Date()`"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
## Run a data exploration script, and see if we cna get chatGPT to describe what it does for us.
```{r, echo=FALSE}
# load packages
require(tidyverse)
require(dplyr)
require(haven)
require(readxl)
```
```{r}
# load data ####
Corn <- read_dta("C:\\Users\\avery\\Downloads\\corn_kynetec_data.dta")
Soy <- read_dta("C:\\Users\\avery\\Downloads\\soy_kynetec_data.dta")
```
```{r}
# Data Cleaning for comparisons #####
# cut down the data to just what is needed to evaluate the recieved code.
# Add crop var, Add uid var
# remove all except:
# CompanyBrand, HybridVariety, year, CompanyParent
Corn_Cut <- Corn %>%
transmute(
uid = row_number(),
crop = "Corn",
year,
HybridVariety,
brandcompany = CompanyBrand, # Stata file will change this
Origbrandcompany = CompanyBrand, # Our variable that will remain the same
companyparent = CompanyParent, # Stata file will change this
OrigcompanyparentLevels = zap_labels(CompanyParent), # preserves the # assignment
OrigcompanyparentFactor = as_factor(CompanyParent) # Shows the company parent name
) %>%
write_dta(path = "C:\\Users\\avery\\Downloads\\CUT_corn_kynetec_data.dta")
Soy_Cut <- Soy %>%
transmute(
uid = row_number(),
crop = "Soy",
year,
HybridVariety,
brandcompany = CompanyBrand, # Stata file will change this
Origbrandcompany = CompanyBrand, # Our variable that will remain the same
companyparent = CompanyParent, # Stata file will change this
OrigcompanyparentLevels = zap_labels(CompanyParent), # preserves the # assignment
OrigcompanyparentFactor = as_factor(CompanyParent) # Shows the company parent name
) %>%
write_dta(path = "C:\\Users\\avery\\Downloads\\CUT_soy_kynetec_data.dta")
```
```{r}
# Load New Data from Ed.P #####
#Corn
Corn_Mask_EdP <- read_dta("C:\\Users\\avery\\Downloads\\Corn_Mask_EdP.dta") %>%
filter(!is.na(acquired)) %>% #Step needed to replace acquired NAs with 1995/6
transmute(
crop,
Origbrandcompany,
OrigcompanyparentLevels = zap_labels(OrigcompanyparentFactor),
OrigcompanyparentFactor = as_factor(OrigcompanyparentFactor),
acquired = acquired+1, # this is for "previously purchased seeds"
orig_comp
) %>%
unique()
#Soy
Soy_Mask_EdP <- read_dta("C:\\Users\\avery\\Downloads\\Soy_Mask_EdP.dta") %>%
filter(!is.na(acquired)) %>% #Step needed to replace acquired NAs with 1995/6
transmute(
crop,
Origbrandcompany,
OrigcompanyparentLevels = zap_labels(OrigcompanyparentFactor),
OrigcompanyparentFactor = as_factor(OrigcompanyparentFactor),
acquired = acquired+1, # this is for "previously purchased seeds",
orig_comp
) %>%
unique()
```
```{r}
# Load Phil Howard Data #####
PH_SalesData <- read_xls(
path = "C:\\Users\\avery\\Desktop\\Research\\Herbicide_Resistance\\BrandWorkspace\\GlobalSeed2018.xls",
sheet = "Sheet3",
range = "A1:C400"
) %>%
transmute(
Owner = toupper(Firm),
Owned = toupper(.[[2]]), # index instead of that awful var name.
Year
) %>%
drop_na() # Drops one obs on line 130 of the .xls
N <- nrow(PH_SalesData)
for (i in 1:N){
a <- PH_SalesData[i,1]
b <- PH_SalesData[i,2]
for (j in i:N) {
if(PH_SalesData[j,1] == b){
PH_SalesData[j,1] <- a
}
}
}
```
```{r}
```