Last updated: 2020-06-30

Purpose

This code is intended to extract and store data on US crop acreage from the US Agricultural Census and USDA’s County Agricultural Production Survey. The census is more comprehensive but is conducted only every 5 years. The annual survey is more frequent but has less comprehensive geographic coverage.

Note: These are large data files (1-6 GB) and this code takes a long time to run.

Data sources

The datasets for both programs were downloaded directly from the ‘back side’ of USDA’s Quick Stats database. The files can be accessed by going to the Quick Stats developer page and clicking the link toward the bottom to download the files. Each file was appended with the download date in the format YYYYMMDD.

  • Files (include Census + CAPS, date is download date)
    • qs.crops.txt
    • qs.economics.txt

Libraries & functions

library(data.table)
library(tidyverse)

Annual crop survey (CAPS)

Crop data

Load data

qs.crops <- fread("../data_big/nass_survey/qs.crops_20200404.txt")
str(qs.crops)

Subset acreage data

# Extract acreage data
# domain_desc=TOTAL excludes acreage data broken down by operation size, etc.

qs.crops.ac <- filter(qs.crops, 
                    UNIT_DESC=="ACRES" &
                      DOMAIN_DESC=="TOTAL")

Subset by geography

with(qs.crops.ac, table(AGG_LEVEL_DESC))
qs.crops.ac.nat <- filter(qs.crops.ac, AGG_LEVEL_DESC=="NATIONAL")
qs.crops.ac.st <- filter(qs.crops.ac, AGG_LEVEL_DESC=="STATE")
qs.crops.ac.cty <- filter(qs.crops.ac, AGG_LEVEL_DESC=="COUNTY")

Save files

write.csv(qs.crops.ac.nat, "../output_big/nass_survey/qs.crops.ac.nat_20200404.csv")
write.csv(qs.crops.ac.st, "../output_big/nass_survey/qs.crops.ac.st_20200404.csv")
write.csv(qs.crops.ac.cty, "../output_big/nass_survey/qs.crops.ac.cty_20200404.csv")

Pastureland, fallow land, and non-ag

Load data

qs.economics <- fread("../data_big/nass_survey/qs.economics_20200404.txt")
str(qs.economics)

Subset acreage data

# Extract acreage data
# domain_desc=TOTAL excludes acreage data broken down by operation size, etc.
# commodity_desc = AG LAND selects only data items having to do with land area
# short_desc = "LAND AREA - INCL, NON-AG - ACRES" selects data items for total land area

qs.economics.ac <- subset(qs.economics, 
                    UNIT_DESC=="ACRES" &
                      DOMAIN_DESC=="TOTAL" &
                      (COMMODITY_DESC=="AG LAND"|SHORT_DESC=="LAND AREA, INCL NON-AG - ACRES"))
str(qs.economics.ac)

Subset by geography

with(qs.economics.ac, table(AGG_LEVEL_DESC))
qs.economics.ac.nat <- filter(qs.economics.ac, AGG_LEVEL_DESC=="NATIONAL")
qs.economics.ac.st <- filter(qs.economics.ac, AGG_LEVEL_DESC=="STATE")
qs.economics.ac.cty <- filter(qs.economics.ac, AGG_LEVEL_DESC=="COUNTY")

Save files

write.csv(qs.economics.ac.nat, "../output_big/nass_survey/qs.economics.ac.nat_20200404.csv")
write.csv(qs.economics.ac.st, "../output_big/nass_survey/qs.economics.ac.st_20200404.csv")
write.csv(qs.economics.ac.cty, "../output_big/nass_survey/qs.economics.ac.cty_20200404.csv")

Session information

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.4.0     stringr_1.4.0     dplyr_0.8.3      
 [4] purrr_0.3.2       readr_1.3.1       tidyr_0.8.3      
 [7] tibble_2.1.3      ggplot2_3.2.0     tidyverse_1.2.1  
[10] data.table_1.12.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1       cellranger_1.1.0 pillar_1.4.2     compiler_3.6.1  
 [5] tools_3.6.1      zeallot_0.1.0    digest_0.6.20    lubridate_1.7.4 
 [9] jsonlite_1.6     evaluate_0.14    nlme_3.1-140     gtable_0.3.0    
[13] lattice_0.20-38  pkgconfig_2.0.2  rlang_0.4.0      cli_1.1.0       
[17] rstudioapi_0.10  yaml_2.2.0       haven_2.1.1      xfun_0.8        
[21] withr_2.1.2      xml2_1.2.0       httr_1.4.0       knitr_1.23      
[25] vctrs_0.2.0      hms_0.5.0        generics_0.0.2   grid_3.6.1      
[29] tidyselect_0.2.5 glue_1.3.1       R6_2.4.0         readxl_1.3.1    
[33] rmarkdown_1.14   modelr_0.1.4     magrittr_1.5     backports_1.1.4 
[37] scales_1.0.0     htmltools_0.3.6  rvest_0.3.4      assertthat_0.2.1
[41] colorspace_1.4-1 stringi_1.4.3    lazyeval_0.2.2   munsell_0.5.0   
[45] broom_0.5.2      crayon_1.3.4    

This R Markdown site was created with workflowr