Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Fwd: Converting weekly data of form yyyyww


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Fwd: Converting weekly data of form yyyyww
Date   Wed, 25 Jul 2012 14:14:31 +0100

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 <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index