Comments (3)
Since fredr
is just a set of R bindings for the FRED API, I'm not sure that sort of function should be included in the package.
However, how far can you get by using either categories or tags to identify a set of series grouped by geography? I'm not entirely sure how well this works for geographies so you'd have to do a little investigation. You could use something like fredr_series_search_tags()
/ fredr_series_search_text()
to find relevant tags or series then map fredr()
over the list of series.
from fredr.
It's all there already if you know where to look! That per-state data is aggregated into a release table, and there is an API for that. The key is finding the release table ID and element ID, which came from the URL.
library(fredr)
library(tidyverse)
# Release table for "Per Capita Personal Income by State, Annual"
# https://fred.stlouisfed.org/release/tables?rid=110&eid=257197
# Note the `rid` and `eid` from the URL!
release <- fredr_release_tables(
release_id = 110,
element_id = 257197
)
series <- release %>%
hoist(value, "series_id", state = "name") %>%
select(series_id, state)
series
#> # A tibble: 51 × 2
#> series_id state
#> <chr> <chr>
#> 1 ALPCPI Alabama
#> 2 AKPCPI Alaska
#> 3 AZPCPI Arizona
#> 4 ARPCPI Arkansas
#> 5 CAPCPI California
#> 6 COPCPI Colorado
#> 7 CTPCPI Connecticut
#> 8 DEPCPI Delaware
#> 9 DCPCPI District of Columbia
#> 10 FLPCPI Florida
#> # … with 41 more rows
#> # ℹ Use `print(n = ...)` to see more rows
series <- series %>%
mutate(obs = map(series_id, fredr_series_observations))
obs <- series %>%
select(-series_id) %>%
unnest(obs)
obs
#> # A tibble: 4,701 × 6
#> state date series_id value realtime_start realtime_end
#> <chr> <date> <chr> <dbl> <date> <date>
#> 1 Alabama 1929-01-01 ALPCPI 319 2022-07-21 2022-07-21
#> 2 Alabama 1930-01-01 ALPCPI 263 2022-07-21 2022-07-21
#> 3 Alabama 1931-01-01 ALPCPI 220 2022-07-21 2022-07-21
#> 4 Alabama 1932-01-01 ALPCPI 159 2022-07-21 2022-07-21
#> 5 Alabama 1933-01-01 ALPCPI 164 2022-07-21 2022-07-21
#> 6 Alabama 1934-01-01 ALPCPI 207 2022-07-21 2022-07-21
#> 7 Alabama 1935-01-01 ALPCPI 216 2022-07-21 2022-07-21
#> 8 Alabama 1936-01-01 ALPCPI 249 2022-07-21 2022-07-21
#> 9 Alabama 1937-01-01 ALPCPI 266 2022-07-21 2022-07-21
#> 10 Alabama 1938-01-01 ALPCPI 242 2022-07-21 2022-07-21
#> # … with 4,691 more rows
#> # ℹ Use `print(n = ...)` to see more rows
obs %>%
filter(state == "Alabama") %>%
ggplot(aes(x = date, y = value)) +
geom_line() +
labs(title = "Per Capita Personal Income in Alabama")
Created on 2022-07-21 by the reprex package (v2.0.1)
from fredr.
This is great - thank you @sboysel and @DavisVaughan
from fredr.
Related Issues (20)
- Unable to Install (Broken Dependency?) HOT 2
- Option to select Seasonally Adjusted Observation HOT 1
- upper bound too low for limit in fredr_category_series() HOT 3
- Pagination HOT 1
- Encoding error with fredr_series_observations HOT 11
- Better test environment for API requests HOT 3
- CRAN issues HOT 25
- Removed from CRAN? HOT 2
- Fredr can't return a legit series_id HOT 3
- Getting fredr back on CRAN HOT 24
- Release fredr 2.0.0
- way to traverse category trees? HOT 4
- This likely isn't an issue with your code, but something to be wary of HOT 3
- Trouble downloading multiple FRED series HOT 5
- fredr() and parameter vintage_dates HOT 5
- M2 not FedFunds
- Release fredr 2.1.0 HOT 1
- fredr appears to be completely broken on my R setup HOT 6
- Capture multiple series simultaneously? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fredr.