girimi839y80904040mkrkellieimimdikiifirimKINOUBIGIAIIOVIubiuuiioioaa ufu Why do we saythat there 52 weeks in a year? [closed] - year0

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
Am I crazy, I've always thought there were 52 weeks in a year, a check on google returns numerous results stating the same...
But if I create a simple spreadsheet, with column A containing 1 to 365 and column B containing INT(A1 / 7) repeated 365 times, column B contains the week index corresponding to the 'julian' day in column A.
The weeks go from 0 to 52, this is actually 53 weeks. If the 1st of January is on day 0, then the 31st of December must overlay into week 1 of the next year.
Can some help explain why we say 52 weeks and not 53?
Sorry I know this isn't strictly a coding question, but is is very relative to a lot of problems with dates and coding.

There are 52 complete weeks in a year. The year has 365 days, leaving one extra day. A leap year has 366 days, adding a second extra day. This makes 52 1/7 weeks in a normal year and 52 2/7 weeks in a leap year..

An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks, that is 364 or 371 days instead of the usual 365 or 366 days. The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term.
The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the (ISO) since 1988 and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.
Weeks start with Monday. Each week's year is the Gregorian year in which the Thursday falls. The first week of the year, hence, always contains 4 January. ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.

Related

How can we match the length of the Gregorian year and the length of the tropical year?

At present the average length of the Gregorian Year over a period of 400 years is 365.2425 days, calculated as follows.
Average length of the Gregorian Year = (97 x 366 + 303 x 365)/ 400 = 365.2425 days
Since the length of the Tropical year is 365 days 5 hours 48 minutes 46 seconds that is, 365 + 20926/8640 = 365.24219907 days, due to which, there is a gap of 0.0003093 day per year, say 0.00031 day per year in them.
It is not at all difficult to bridge even this gap, by shedding one more leap year over a period of 3226 years, calculated in the following manner.
Supposing it has to be shed over N years — we can, very easily, calculate the value of N, as follows.
N = 1/0.00031 = 3225.8 years, say, 3226 years.
Since it has already covered 438 years since the year 1582 AD obviously, we can synchronise both years by shedding one more leap year over the next “3226 – 438” years, that is, by October 5, 4808.
I would recommend that the International Astronomical Society may take cognisance of this possibility.

Representing an entire day or week or month as a number like timestamp

How can a day or week or month, essentially a range of time be represented by a single number?
The next interval would represent a number 1 more than the number for the previous interval, just how the next second is 1 more than the previous second, in timestamp representation.
Given a bunch of such numbers, the larger number simply means its representing a time interval afterwards in time, when compared to a number smaller than it.
Just realized if I stick to UTC and represent the day as YYYYMMDD, this becomes a number that I am looking for.
20180420 // 20 april 2018
20180421 // 21 april 2018
20180510 // 10 may 2018
20190101 // 1 jan 2019
This works for representing a day perfectly, I think.
For week, maybe do ceil() of days of current month divided by 7 for representing week as a number W and then using the format: YYYYMMW.
2018043 // 3rd week of april 2018
2018045 // 5th week of april 2018, though may not be the 5th week semantically but representation model works, greater than 4th week of april 2018 and smaller number than 1st week of may 2018
For month, simply YYYYMM works.
I feel so smart right now! 😄

Determine week number from date over several years

I'm looking for a way to determine the week number (week beginning on Monday) over several years. That means I don't want to have 0-53 but if, let's say I have 2 years of dates, I want them to be numbered with 0-106 in R.
I tried strftime(Datum, format ="%W") but then I only get the annual week number and not as a whole.
Given that you did not provide any data, I took the liberty of creating some:
#create data
Datum<-c("2013-03-01", "2014-06-02", "2013-06-01")
# format data to year-month-day with strptime
Datum<-strptime(Datum, "%Y-%m-%d")
You now need to identify the origin year. As I'm sure you are aware not all years have the same number of weeks 52.29 in a leap year vs. 52.4 in a standard calendar year but as this is unlikely to be a consideration for only 2 years we can use the number of weeks returned through the strftime function.
origin.year=as.numeric(min(substring(Datum,1,4)))
# number of weeks in first year (offset for second year)
n.weeks<-52
Now we can create a vector containing the number of weeks to offset each week in Datum (X).
X<-as.numeric(substring(Datum,1,4)!=origin.year)*n.weeks
We can then simply add this vector to the number of weeks returned by strftime when it is applied to Datum
week.vec<-as.numeric(strftime(Datum, "%W"))+X
This will work for 2 years, but if you have more years than this, you will need to modify the offsets to account for this.

Post-Process a Stata %tw date in R

The %tw format in Stata has the form: 1960w1 which has no equivalent in R.
Therefore %tw dates must be post-processed.
Importing a .dta file into R, the date is an integer like 1304 (instead of 1985w5) or 1426 (instead of 1987w23). If it was a simple time series you could set a starting date as follows:
ts(df, start= c(1985,5), frequency=52)
Another possibility would be:
as.Date(Camp$date, format= "%Yw%W" , origin = "1985w5")
But if each row is not a single date, then you must convert it.
The package ISOweek is based on ISO-8601 with the form "1985-W05" and does not process the Stata %tw.
The Lubridate package does not work with this format. The week() returns the number of complete seven day periods that have occurred between the date and January 1st, plus one. week function
In Stata week 1 of any year starts on 1 January, whatever day of the week that is. Stata Documentation on Dates
In the format %W of Date in R the week starts as Monday as first day of the week.
From strptime %V is
the Week of the year as decimal number (00--53) as defined in ISO
8601. If the week (starting on Monday) containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise,
it is the last week of the previous year, and the next week is week 1.
(Accepted but ignored on input.) Strptime
Larmarange noted on Github that Haven doesn't interpret dates properly:
months, week, quarter and halfyear are specific format from Stata,
respectively %tm, %tw, %tq and %th. I'm not sure that there are
corresponding formats available in R. So far they are imported as
integers.
Is there a way to convert Stata %tw to a date format R understands?
Here is an Stata file with dates
This won't be an answer in terms of R code, but it is commentary on Stata weeks that can't be fitted into a comment.
Strictly, dates in Stata are not defined by the display formats that make them intelligible to people. A date in Stata is always a numeric variable or scalar or macro defined with origin the first instance in 1960. Thus it is at best a shorthand to talk about %tw dates, etc. We can use display to see the effects of different date display formats:
. di %td 0
01jan1960
. di %tw 0
1960w1
. di %tq 0
1960q1
. di %td 42
12feb1960
. di %tw 42
1960w43
. di %tq 42
1970q3
A subtle point made explicit above is that changing the display format will not change what is stored, i.e. the numeric value.
Otherwise put, dates in Stata are not distinct data types; they are just integers made intelligible as dates by a pertinent display format.
The question presupposes that it was correct to describe some weekly dates in terms of Stata weeks. This seems unlikely, as I know no instance in which a body outside StataCorp uses the week rules of Stata, not only that week 1 always starts on 1 January, but also that week 52 always includes either 8 or 9 days and hence that there is never a week 53 in a calendar year.
So, you need to go upstream and find out what the data should have been. Failing some explanation, my best advice is to map the 52 weeks of each year to the days that start them, namely days 1(7)358 of each calendar year.
Stata weeks won't map one-to-one to any other scheme for defining weeks.
More in this article on Stata weeks
It's not completely clear what the question is but the year and week corresponding to 1304 are:
wk <- 1304
1960 + wk %/% 52
## [1] 1985
wk %% 52 + 1
## [1] 5
so assuming that the first week of the year is week 1 and starts on Jan 1st, the beginning of the above week is this date:
as.Date(paste(1960 + wk %/% 52, 1, 1, sep = "-")) + 7 * (wk %% 52)
## [1] "1985-01-29"

Epidemiological curve using R and epitools gives wrong epiweeks

I have been trying to make epidemic curves in R with the epitools package. According to the documentation, you can automatically generate epidemiological weeks from a date variable, similar as I have been doing for long in STATA. Fyi, epidemiological weeks are different from yearly week numbers:
The first epi week of the year ends, by definition, on the first
Saturday of January, as long as it falls at least four days into the
month. Each epi week begins on a Sunday and ends on a Saturday.
http://www.cmmcp.org/epiweek.htm
https://wiki.ecdc.europa.eu/fem/f/1287/p/576/681.aspx#681
graphlabels<-epicurve.weeks(DATE_variable,
axisnames=FALSE,
xlab = "Week of Year",
ylab = "Cases per week",
tick.offset = 0.5,
col=mypalette)
axis(1,
at = graphlabels$xvals,
labels = graphlabels$cweek,
tick = FALSE,
line = 0,
)
This automatically generated a nice curve:
"Hurray!!", I thought. But, alas, being a scientist I double checked the data using STATA as well as manually and noticed that the data does not correspond!
Am I doing something wrong with epitool package that it gives me wrong epic weeks?
After some further discussion and research, there are differences in how epidemiological weeks can be calculated.
EPITOOLS as.week
In public health, reportable diseases are often reported by 'disease
week' (either week of reporting or week of symptom onset). In R, weeks
are numbered from 0 to 53 in the same year. The first day of week 1
starts with either the first Sunday or Monday of the year. Days before
week 1 are numbered as 0s. In contrast to R, the as.week function
generates weeks numbered from 1 to 53. The week before week 1 takes on
the value (52 or 53) from the last week of the previous year. The
as.week functions facilitates working with multiple years and
generating epidemic curves.
MMWR week
Values for MMWR week range from 1 to 53, although most years consist
of 52 weeks. The first day of any MMWR week is Sunday. MMWR week
numbering is sequential beginning with 1 and incrementing with each
week to a maximum of 52 or 53. MMWR week #1 of an MMWR year is the
first week of the year that has at least four days in the calendar
year. For example, if January 1 occurs on a Sunday, Monday, Tuesday or
Wednesday, the calendar week that includes January 1 would be MMWR
week #1. If January 1 occurs on a Thursday, Friday, or Saturday, the
calendar week that includes January 1 would be the last MMWR week of
the previous year (#52 or #53). Because of this rule, December 29, 30,
and 31 could potentially fall into MMWR week #1 of the following MMWR
year.
EPIWEEK for STATA
Each epidemiological week begins on a Sunday and ends on Saturday. And
the first epidemiological week of year ends on the first Saturday of
January, provided that it falls at least four or more days into the
month
ISO (or business) week
An ISO week-numbering year (also called ISO year informally) has 52 or
53 full weeks. That is 364 or 371 days instead of the usual 365 or 366
days. The extra week is referred to here as a leap week, although ISO
8601 does not use this term. Weeks start with Monday. The first week
of a year is the week that contains the first Thursday of the year
Week "u" in SAS
Each epidemiological week begins on a Sunday and ends on Saturday. And
the first epidemiological week of year contains Sunday. Weeks range
from 0 to 53 but do not always count 7 days

Resources