Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Ruth Gilgenbach <rgrune@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Fwd: Converting weekly data of form yyyyww |
Date | Wed, 25 Jul 2012 09:31:48 -0500 |
Thanks for your quick reply. This was helpful--I didn't realize that's what -encode- does. I'm sure there's a more elegant solution, but something like: ****************** gen year = substr(dates,1,4) destring year, replace gen week = substr(dates,5,2) destring week, replace gen delivery =yw(year,week) format %tw delivery ******************* works, except for the week 53 problem. On Wed, Jul 25, 2012 at 8:14 AM, Nick Cox <njcoxstata@gmail.com> wrote: > > Don't -encode-, -destring-, or use -real()- directly, which avoids > creation of new variables. For example, -encode- would map "2009", "2010", > "2011" to 1,2,3, not at all what you want. > > Mapping anybody's else "weeks" onto Stata's weeks is still going to be a > problem, however. > > > On 25 Jul 2012, at 13:55, Ruth Gilgenbach <rgrune@gmail.com> wrote: > >> I have a data set with variable "dates" which are of the form yyyyww, >> and I am trying to convert them to a useable format, and am having no >> luck. I am running Stata 12. >> >> For example, if I use the following >> ************************ >> inp str06 dates >> 201002 >> 200953 >> 201102 >> 200935 >> end >> >> gen delivery = weekly(dates,"YW") >> ************************* >> >> I get the result: (4 missing values generated) rather than the correct >> result. >> >> I know that the 53-week year in 2009 is also going to pose a problem, >> but this problem persists even in the absence of week 53. >> >> I have also attempted to split the string into components and build >> the dates from these, but I receive the same problem, that missing >> values are generated rather than the values themselves: >> >> ****************** >> inp str06 dates >> 201002 >> 200953 >> 201102 >> 200935 >> end >> >> gen year =substr(dates,1,4) >> encode year, generate(nyear) >> gen week = substr(dates,5,2) >> encode week, generate(nweek) >> >> gen delivery2 = yw(nyear,nweek) >> ********************************* >> >> > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/