Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Translate Google Trends date system into Stata date system

From   Phil Schumm <>
To   <>
Subject   Re: st: Translate Google Trends date system into Stata date system
Date   Wed, 1 May 2013 12:09:06 -0500

On May 1, 2013, at 11:21 AM, Sergiy Radyakin wrote:
> tempvar d1 d2
> generate `d1'=substr(googledate,1,10)


On May 1, 2013, at 11:41 AM, Nick Winter wrote:
> Or, for maximum concision (and obfuscation):
> forval i=1/2 {
>  generate date`i' = date(substr(googledate, 12-11*`i' ,10),"YMD")
>  format date`i' %td
> }

As long as we're beating this poor horse, I would note that while using -substr()- is perfectly fine if the format of your input is guaranteed (as it may well be with Google Trends), it can be dangerous in cases where it is not (i.e., silently returning an undesired value).  Using a regular expression to extract the information (as I suggested) is safer in such cases, and in fact, can often be easily modified to work even in cases where the format of the input varies slightly (assuming that the desired information is still present).  Finally, some might argue that it is more readable, since a call to -substr()- tells you nothing about what you are expecting to encounter in the input.

-- Phil

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index