You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
collector <- list()
collect_industry <- dplyr::data_frame()
for (j in seq_along(state)) {
st <- state[[j]]
for (k in seq_along(year)) {
yr <- year[[k]]
for (i in seq_along(industry)) {
ind <- industry[[i]]
url <-paste("https://api.census.gov/data/timeseries/qwi/sa?get=",
"Emp,EmpEnd,HirA,Sep,FrmJbC,FrmJbCS,FrmJbGn,FrmJbLs,sEmp,sEmpEnd,sHirA,sSep,sFrmJbC,sFrmJbCS,sFrmJbGn,sFrmJbLs,EarnS,EarnBeg,EarnHirAS,EarnHirNS,EarnSepS,sEarnS,sEarnBeg,sEarnHirAS,sEarnHirNS,sEarnSepS",
"&for=metropolitan+statistical+area/micropolitan+statistical+area",
"&in=state:",st,
"&year=",yr,
"&quarter=1&quarter=2&quarter=3&quarter=4",
"&sex=0",
"&agegrp=A00",
"&ownercode=A05",
"&firmage=1&firmage=2&firmage=3&firmage=4&firmage=5",
"&seasonadj=U&",
"industry=",ind,
"&key=",census_key,
sep="")
call <- httr::GET(url)
#print(call$status_code)
if(!call$status_code %in% c(200, 202)){
# 500 means that message failed If not 500 then there was an OK
next(i)
print(call$status_code)
print(url)
} else{
# Keep going if there isn't an error
dat <- dplyr::as_data_frame(
jsonlite::fromJSON(
httr::content(call, as = "text")))
colnames(dat) <- dat[1, ]
dat <- dat[-1, ]
# Keep adding to the data frame
collect_industry <- dplyr::bind_rows(collect_industry, dat)
}
}
# Store for each state into a list
collector[[i]] <- collect_industry
}
}
And for firmsize:
collector <- list()
collect_industry <- dplyr::data_frame()
for (j in seq_along(state)) {
st <- state[[j]]
for (k in seq_along(year)) {
yr <- year[[k]]
for (i in seq_along(industry)) {
ind <- industry[[i]]
url <-paste("https://api.census.gov/data/timeseries/qwi/sa?get=",
"Emp,EmpEnd,HirA,Sep,FrmJbC,FrmJbCS,FrmJbGn,FrmJbLs,sEmp,sEmpEnd,sHirA,sSep,sFrmJbC,sFrmJbCS,sFrmJbGn,sFrmJbLs,EarnS,EarnBeg,EarnHirAS,EarnHirNS,EarnSepS,sEarnS,sEarnBeg,sEarnHirAS,sEarnHirNS,sEarnSepS",
"&for=metropolitan+statistical+area/micropolitan+statistical+area",
"&in=state:",st,
"&year=",yr,
"&quarter=1&quarter=2&quarter=3&quarter=4",
"&sex=0",
"&agegrp=A00",
"&ownercode=A05",
"&firmsize=1&firmsize=2&firmsize=3&firmsize=4&firmsize=5",
"&seasonadj=U&",
"industry=",ind,
"&key=",census_key,
sep="")
call <- httr::GET(url)
#print(call$status_code)
if(!call$status_code %in% c(200, 202)){
# 500 means that message failed If not 500 then there was an OK
next(i)
print(call$status_code)
print(url)
} else{
# Keep going if there isn't an error
dat <- dplyr::as_data_frame(
jsonlite::fromJSON(
httr::content(call, as = "text")))
colnames(dat) <- dat[1, ]
dat <- dat[-1, ]
# Keep adding to the data frame
collect_industry <- dplyr::bind_rows(collect_industry, dat)
}
}
# Store for each state into a list
collector[[i]] <- collect_industry
}
}
The text was updated successfully, but these errors were encountered:
For firmage:
And for firmsize:
The text was updated successfully, but these errors were encountered: