Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get data for 2017 #12

Closed
pedromein opened this issue Mar 16, 2018 · 6 comments
Closed

Can't get data for 2017 #12

pedromein opened this issue Mar 16, 2018 · 6 comments

Comments

@pedromein
Copy link

I'm not able to get data for 2017 on, already updated database. For Exemple
example1 <- ct_search(reporters = "Canada", partners = "Brazil", trade_direction = "exports", start_date = "2017-01-01", end_date = "2018-01-01")
Will return a data frame with no observations.

@ChrisMuir
Copy link
Member

That specific query is returning an empty data frame because the Comtrade API doesn't return data for that query. If you go to the Comtrade API query website, plug in your search parameters and hit the "Preview" button, you'll see that there are zero results returned.

Comtrade relies on reporting from individual countries to update their DB, so sometimes posting of new data can seem slow.

Also, for annual versus monthly data, I believe they hold off on publishing annual data until they've received data for all (most?) months for a given year. For example, this query returns zero results:

df <- comtradr::ct_search(reporters = "USA", 
                          partners = "World", 
                          freq = "annual", 
                          start_date = 2017, 
                          end_date = 2017)

While this query returns a df with nine observations (one row each for imports, exports, and Re-exports, times three months):

df <- comtradr::ct_search(reporters = "USA", 
                          partners = "World", 
                          freq = "monthly", 
                          start_date = "2017-01", 
                          end_date = "2017-03")

@pedromein
Copy link
Author

Thank you. I've failed to realize that.
One last question if you allow, you use a date arguments without the format 'yyy-mm-dd' that is just a simplification or the program will run properly? If so, do exist a command for "all of 'year'" which is a valid parameter in the Comtrade API query website?

@pedromein pedromein reopened this Mar 16, 2018
@ChrisMuir
Copy link
Member

No worries!

Yeah the ability to pass date args that are not in the format "yyyy-mm-dd" is a very recent update I pushed to the GitHub repo in the last month (see issue #10). If you install the dev version from GitHub, you can use this new feature (and I'll send a new release to CRAN at some point in the near future).

In ct_search(), if you search for annual data, you can set the start_date and end_date to a single year (like 2017 in my example), and this is equivalent to searching "all of year". I hope this answers your question.

@pedromein
Copy link
Author

The "all of 'yyyy'" parameter gives all months of that year if the data is set to monthly. Is a parameter under 'Periods' witch makes more viable to create long monthly series since you can search 12 months each time, instead of 5.

@ChrisMuir
Copy link
Member

Ahhh, I now see what you're talking about....woah I've never seen the All of yyyy options for monthly data! I don't know if that's a new API feature or I just missed it before, but thank you for pointing it out. Either way, yeah I will for sure be updating ct_search to allow for this query option. I'll open a new issue and work on it sometime in the next week.

In the meantime, I think you can recreate the All of yyyy search by doing something like this:

# Simulate the "All of 2016" monthly search
library(dplyr)
df <- comtradr::ct_search("USA", "China", 
                          freq = "monthly", 
                          start_date = "all", 
                          end_date = "all") %>% 
  filter(year == 2016)

@ChrisMuir
Copy link
Member

Function ct_search() is now able to utilize the All of yyyy feature of the Comtrade API (added via commit 8f6f3bf).

So going back to my previous example:

# Simulate the "All of 2016" monthly search
library(dplyr)
df <- comtradr::ct_search("USA", "China", 
                          freq = "monthly", 
                          start_date = "all", 
                          end_date = "all") %>% 
  filter(year == 2016)

This query is now equivalent (all monthly data for 2016):

df <- comtradr::ct_search("USA", "China", 
                          freq = "monthly", 
                          start_date = 2016, 
                          end_date = 2016)

Thanks again @pedromein for bringing this API feature to my attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants