PMassicotte / gtrendsR

R functions to perform and display Google Trends queries
352 stars 112 forks source link

Gtrends is not getting the most recent data #448

Closed marcelobfr closed 1 year ago

marcelobfr commented 1 year ago

I was running gtrends(keyword='unemployment claims',geo="US") to get the weekly data from the last 5 years and the last observation is from 4/8/2023 (14th week of 2023). However, when you go to the google trends webpage, you have data from the 4/15/2023 (15th week of 2023). How can I get the most recent available data?

image

eddelbuettel commented 1 year ago

That is possibly related to how the time span for that query is constructed. If you do help(gtrends) and pick another less setting you get the data:

> res2 <- gtrends(keyword='unemployment claims',geo="US", time="today 1-m") 
> tail(res2[[1]])
         date hits             keyword geo      time gprop category
23 2023-04-10   21 unemployment claims  US today 1-m   web        0
24 2023-04-11    0 unemployment claims  US today 1-m   web        0
25 2023-04-12   18 unemployment claims  US today 1-m   web        0
26 2023-04-13   87 unemployment claims  US today 1-m   web        0
27 2023-04-14   25 unemployment claims  US today 1-m   web        0
28 2023-04-15   24 unemployment claims  US today 1-m   web        0
> 

So I suggest you look into a more explicit or different time specification. Or maybe do an 'outer' coarse one and combine it (carefully -- they do odd things to normalize their peaks to 100) with a more fine-grained recent one.

marcelobfr commented 1 year ago

Thanks! But i would like to get weekly time series. They are more reliable than getting more granular recent data and combine as things can get tricky (just as you said). My point is: Is that a bug from the function or a limitation imposed by google trends or the author?

JBleher commented 1 year ago

You can aggregate any time series that you'd like. You will just need to make sure that your concatenation approach delivers a coherent time series. See https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3357424 for details.

Depending on the specified time frame google will deliver a certain frequency. For longer time spans only monthly data are available. You can have weekly data up to 5 years.

Concerning your last question the following query will deliver the result that you'd like: gtrends(c("unemployment claims"), time = "2018-04-20 2023-04-20",onlyInterest = TRUE)

PMassicotte commented 1 year ago

@marcelobfr Can you verify that the solution provided by @JBleher works for you?

marcelobfr commented 1 year ago

Yes! Thank you @JBleher