Output of usdarnass

  collapse = TRUE,
  eval = !(Sys.getenv("NASS_KEY") == ""),
  comment = "#>"


Each successful call of the nass_data() command will return a data.frame object with 39 variables, although a handful of these variables will have the same value for each observation in the data.frame due to the nature of setting parameters for a query. The resulting data.frame is of the long variety with the Value variable as the numerical variable of interest for the query.

Official USDA Objects

The official documentation for each of these variables from the USDA are as follows:

I learn best through examples, so I'll cover a few different levels of analysis and subtleties related to the data.

County Level Example

We can set a query where we return all data at the county level in Ohio related to rent, which is equivalent to https://quickstats.nass.usda.gov/ setting "Geographic Level" to COUNTY, "State" equal to Ohio, and "Commodity" equal to RENT :

library("dplyr") # Helpful package

ohio_rent <- nass_data(commodity_desc = "RENT", agg_level_desc = "COUNTY",
                       state_name = "OHIO")

The agg_level_desc, commodity_desc, and state_name variables are all the same because the query parameters were set on those values. It turns out a few other variables will be identical for the whole data.frame because they do not vary based on county level observations in Ohio: country_code, state_alpha, state_ansi, and state_fips_code.

There are a fair amount of other variables which are all the same for the entire data.frame, but these variables are not the same because of the regional aggregation variables but because we have subset the data by the commodity_desc as "RENT".

The various other parameters that we could have set in this query of interest are from the short_desc parameter, which we could use the nass_param() function to view the options for this data item:

nass_param("short_desc", commodity_desc = "RENT", agg_level_desc = "COUNTY", state_name = "OHIO")

Alternatively, in the previously returned query with the nass_data() function, we could view the frequency of the different short_desc variables to get to the same outcome but with the additional benefit of knowing the number of observations:


Dominant form of rent in Ohio

In Ohio, the dominant form of cash rent is for non-irrigated cropland and most counties in Ohio are surveyed in the state and have a usable value for cash rent in a year. But this is not exactly right, so we can see this by subsetting our original query for only non-irrigated cropland and look at the number of counties in each year's observation.

non_irrigated <- ohio_rent %>% 
  filter(grepl("NON-IRRIGATED", short_desc))
table(non_irrigated$year) # Observation per year

The cash rent values begin in 2008 with a small subset of counties in Ohio and then cover the vast majority of the state in 2009 onward. As it turns out, the entire state is surveyed but some counties do not have enough observations to have a statistically relevant sample and are thus combined at the agricultural reporting district level. This can be see with a listing of all of the counties in Ohio with rent data available:

# nass_param("county_name", state_name = "OHIO")

The "OTHER (COMBINED) COUNTIES" value has by far and away the most observations over this time and, if one knows all of the counties in Ohio, there are a few missing counties that we need to input their values for. Each of the "OTHER (COMBINED) COUNTIES" values is for a specific agricultural reporting district:

non_irrigated %>%
  filter(county_name == "OTHER (COMBINED) COUNTIES") %>%
  pull(asd_code) %>%

There are nine reporting districts in Ohio and eight of the nine have observations which combine counties for an observation -- which implies some counties are missing official observations for the statistics in question. It is not necessarily the case that the counties are completely missing but they are suppressed. One method for correcting for these missing values is to replace the missing counties with the "OTHER (COMBINED) COUNTIES" category for average rent.

In order to do this, we first need a full set of all of the counties in Ohio along with their corresponding agricultural district number. There are many ways to accomplish this, but I will go about this by leveraging the 2012 Agricultural Census data which is in Quick Stats and contains a category for the number of farms in each Ohio county. The number of farms is not helpful for our data concerns but it does serve as a way to return a data.frame with 88 observations in Ohio with each uniquely corresponding to a county in Ohio.

farms <- nass_data(source_desc = "CENSUS", year = 2012, state_name = "OHIO", agg_level_desc = "COUNTY", domain_desc = "TOTAL", short_desc = "FARM OPERATIONS - NUMBER OF OPERATIONS")

At this point, we want to make sure that each year for our non_irrigated rent data has all 88 counties with an NA value if it does not exist. Then, we want to impute the "OTHER (COMBINED) COUNTIES" category for all of the NAs. To do this we will create the backbone of our desired observations from the farms and then fully merge this with the current data from Quick Stats. The resulting data.frame will have missing "Value" observations for the counties which do not have observations and we will impute the value from "OTHER (COMBINED) COUNTIES". And last of all, with these data the only important aspect of these observations is that we have a county identifier, locational aspects, and the year in question. Much of the rest of the variables in the dataset are not of importance to us so we will have only keep the remaining important variables and convert them to numeric.

base_rent <- farms %>% 
  select(state_fips_code, county_code, county_name, asd_code, asd_desc) %>% 
  expand(year = unique(non_irrigated$year), nesting(state_fips_code, county_code, county_name, asd_code)) %>% 

# Correct for missing values in the "other"
base_rent <- base_rent %>% 
  arrange(year, asd_code, county_code) %>% 
  group_by(year, asd_code) %>% 
  mutate(Value = ifelse(is.na(Value), Value[county_code == "998"], Value)) %>% 
  filter(county_code != "998")

# Finally, select only the relevant variables are rename
base_rent <- base_rent %>% 
  select(year, state_fips_code, county_code, county_name, asd_code, rent = Value) %>% 
  mutate(rent = as.numeric(rent),
         fips = as.numeric(paste0(state_fips_code, county_code)))


Try the usdarnass package in your browser

Any scripts or data that you put into this service are public.

usdarnass documentation built on June 21, 2019, 9:06 a.m.